Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
In bash how can I make a construction like this to work:
if (cp /folder/path /to/path) && (cp /anotherfolder/path /to/anotherpath)
echo "Succeeded"
echo "Failed"
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"
echo "not"
cp /folder/path /to/path && cp /anotherfolder/path /to/anotherpath
if [ $? -eq 0 ] ; then
echo "Succeeded"
echo "Failed"
–
–
–
I tested it :
david@pcdavid:~$ cp test.tex a && cp test.aux b && { echo "haha"; } || { echo "hoho"; }
david@pcdavid:~$ cp test.ztex a && cp test.aux b && { echo "haha"; } || { echo "hoho"; }
cp: cannot stat `test.ztex': No such file or directory
david@pcdavid:~$ cp test.tex a && cp test.zaux b && { echo "haha"; } || { echo "hoho"; }
cp: cannot stat `test.zaux': No such file or directory
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.