How can I make this if's work in Bash?
In bash how can I make a construction like this to work:
if (cp /folder/path /to/path) && (cp /anotherfolder/path /to/another开发者_开发知识库path)
then
echo "Succeeded"
else
echo "Failed"
fi
The if should test for the $? return code of each command and tie them with &&.
How can I make this in Bash ?
if cp /folder/path /to/path /tmp && cp /anotherfolder/path /to/anotherpath ;then
echo "ok"
else
echo "not"
fi
cp /folder/path /to/path && cp /anotherfolder/path /to/anotherpath if [ $? -eq 0 ] ; then echo "Succeeded" else echo "Failed" fi
Another way :
cp /folder/path /to/path && cp /anotherfolder/path /to/anotherpath && {
echo "suceeded"
} || {
echo "failed"
}
I tested it :
david@pcdavid:~$ cp test.tex a && cp test.aux b && { echo "haha"; } || { echo "hoho"; }
haha
david@pcdavid:~$ cp test.ztex a && cp test.aux b && { echo "haha"; } || { echo "hoho"; }
cp: cannot stat `test.ztex': No such file or directory
hoho
david@pcdavid:~$ cp test.tex a && cp test.zaux b && { echo "haha"; } || { echo "hoho"; }
cp: cannot stat `test.zaux': No such file or directory
hoho
精彩评论