hi i am having a acript for which i need to skip the execution of some lines and to continue with remaining lines for eg
script.sh
rm text
for i in *
do
.
.
.
.
.
if [x = y]
then
rm
i want to skip the execution of the lines and to start with
if [x = y]
then
rm
Put them in a condition thats never true.
if [ 1 == 0 ];then
script.sh
rm text
for i in *
do
.
.
.
.
.
done
fi
if [x = y]
then
rm
Put comment signs in front of the lines:
# rm text
# for i in *
# do
# .
# .
# .
# .
# done
# .
if [x = y]
then
rm
1 Like
hi
i dont wanted to comment each line since the script is very huge
If you dont want to comment it out, then you can use the "if" condition.
Well, if you use vi
you can use:
:1,/if \[x = y\]/s/^/# /
And then delete the last comment...
--
The correct syntax is
if [ 1 = 0 ]; then
But you could also use:
if [ ]; then
or
if false; then
1 Like
RudiC
May 2, 2014, 6:39am
7
If your shell allows for here documents, you could try
script.sh
<<EOF
rm text
for i in *
do
.
.
.
.
.
EOF
if [x = y] then rm
Make sure that the token (here:EOF) does not occur anywhere in the portion to be skipped.
If you use a here-document construct for that, also make sure that there quotes around the first EOF ( <<"EOF"
), otherwise parameter expansion, command substitution, and arithmetic expansion will still occur within that block.
1 Like
RudiC
May 2, 2014, 7:30am
9
True, Scrutinizer. But that wouldn't hurt, would it? Except for some waste of CPU- ressourses?
Well command substitution might hurt, depending on what is being done inside. Anyway I would not want to leave that to chance..
Parameter substitution includes $() and backticks. It could well end up doing something...
Not sure if this might be an idea...
Create a function from the __unwanted__ code:-
unused()
{
# All your temporary code here...
}
EDIT:
As a bonus if you need it you can call it...