magento
asked on
Exit is not working in shellcode
Hi,
I will check if directory exists, if yes it should run the copy command.
If copy fails,then it should echo "Failed" and exit the script.
But it not exiting and run the next shell script.
I also tried below
I will check if directory exists, if yes it should run the copy command.
If copy fails,then it should echo "Failed" and exit the script.
But it not exiting and run the next shell script.
I also tried below
( cp "DIRECTORY"/* "ADIRECTORY" && echo copy; ) || ( echo "Failed" && exit 1)
but it also not working as expected.When the cp operation success it should echo copy and run product.sh ,when cp operation failed it should echo Failed and exit the script and not running product.sh Maincode:
if [[ -d DIRECTORY && -d ADIRECTORY ]];
then
( cp "DIRECTORY"/* "ADIRECTORY" && echo copy; ) || ( echo "Failed" ; exit 1;)
source product.sh ;
else
echo "Dir not found ";
exit 1;
fi
Since you are using or, once the first part is true, the second is not evaluated.
You should use the cp as the condition of an IF statement.
Not sure what you are looking at.
You should use the cp as the condition of an IF statement.
Not sure what you are looking at.
ASKER
Hi,
I run as bash -x script.sh
It goes to line exit 1, but not exiting.
+++echo failed
++exit 1
++source product.sh
Thanks
I run as bash -x script.sh
It goes to line exit 1, but not exiting.
+++echo failed
++exit 1
++source product.sh
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you wanted to have the execution of product.sh if one of the conditions was met add an &&
Cp && source product.sh if you still need the echo responsess.
Any reason why an absence of either directory you not use mkdir -p to create them?
Cp && source product.sh if you still need the echo responsess.
Any reason why an absence of either directory you not use mkdir -p to create them?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Maincode:
if [[ -d DIRECTORY && -d ADIRECTORY ]];
then
( cp "DIRECTORY"/* "ADIRECTORY" && echo copy; ) && source product.sh ;
else
echo "Dir not found ";
exit 1;
fi
sh -x scripfiletname