How can I do this if I work in Bash?

In bash, how can I do this construct:

if (cp /folder/path /to/path) && (cp /anotherfolder/path /to/anotherpath) then echo "Succeeded" else echo "Failed" fi 

If you need to check the value of $? return the code of each command and associate them with & &.

How can I do this in bash?

+4
source share
3 answers
 if cp /folder/path /to/path /tmp && cp /anotherfolder/path /to/anotherpath ;then echo "ok" else echo "not" fi 
+13
source
  cp / folder / path / to / path && cp / anotherfolder / path / to / anotherpath
 if [$?  -eq 0];  then
     echo "Succeeded"
 else
     echo "Failed"
 fi
+8
source

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 
+2
source

Source: https://habr.com/ru/post/1304980/


All Articles