Im trying to do something like this but I cant find any documentation.
read X
if [ $X = 1 ]
then goto ThisLine
fi
OTHER CODE
OTHER CODE
Label: ThisLine echo "You entered 1"
Im trying to do something like this but I cant find any documentation.
read X
if [ $X = 1 ]
then goto ThisLine
fi
OTHER CODE
OTHER CODE
Label: ThisLine echo "You entered 1"
you can use the goto statement in Csh but other shells like ksh,sh (not supported).
Any work arounds you could think of?
You can create function and call the function.
#!/bin/sh
ThisLine() {
echo "You entered 1"
return 0
echo "I wasn't executed because on the return command :("
}
read X
if [ $X = 1 ]; then
ThisLine
echo 'Done!'
fi
exit 0
Here is an example on your code using a function instead of a goto
function needs to be created before the main code, else you get ./script.sh: 6: ThisLine: not found
return is optional if it is placed at the end of the function
you can put an argument after the return, defining the exit status of the function
Thanks for the help!