I am Installing multiple packages by using && operator for stopping execution of succeeding one if preceding one fails. && function is working when all written in single line.
But When they written in line by line && function is not working and I am getting error. My code is like this:
yum -y install XXZ \
&& yum -y install rsync \
&& yum -y install libxml2-devel \
&& yum -y install ntp
The Error is:
install5.sh: line 4: syntax error near unexpected token `&&'
'nstall5.sh: line 4: `&& yum -y install rsync \
How to stop the execution of successive one if preceding one fails by using && operator when the commands are written in line by line(not in a single line).?
Please Help!
$? stores exit code of last command. You can do the following in a script:
yum -y install XXZ
if [[ $? != "0" ]] ## exit code other than zero
then
## your code for failure
exit
fi
yum -y install rsync
if [[ $? != "0" ]]
then
## your code for failure
exit
fi
Do the same for all packages. I recommend you to make an array and use for loop. Exit code zero means success. Hope this helped.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments