Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make this if's work in Bash?

Tags:

linux

bash

shell

In bash how can I make a construction like this to work:

if (cp /folder/path /to/path) && (cp /anotherfolder/path /to/anotherpath)
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 ?

like image 243
Dragos Avatar asked Nov 28 '22 19:11

Dragos


2 Answers

if cp /folder/path /to/path /tmp && cp /anotherfolder/path /to/anotherpath ;then
  echo "ok"
else
  echo "not"
fi
like image 51
ghostdog74 Avatar answered Jan 22 '23 03:01

ghostdog74


cp /folder/path /to/path && cp /anotherfolder/path /to/anotherpath
if [ $? -eq 0 ] ; then
    echo "Succeeded"
else
    echo "Failed"
fi
like image 43
Michael Aaron Safyan Avatar answered Jan 22 '23 03:01

Michael Aaron Safyan