I have test.sh which has multiple return condition and test1.sh just echo statement.When i run test2.sh my logic should run test.sh process the file i.e "File successfully" and call test1.sh script .It should not run the test1.sh script when other else condition was executed.i.e "File not successfully", "Input file doesn't exists in directory"
The problem i am facing is when it is executing other condition like "File not successfully", "Input file doesn't exists in directory" it is not retuning "1" as specified exit code but in turn returning 0 i.e from the OS means job was successful. So i am getting "0" from test.sh for all the different condition so test1 .sh is getting called irrespective if the file processed failed etc.Pls advice with the return code
test.sh
FILES=/export/home/input.txt
cat $FILES | nawk -F '|' '{print $1 "|" $2 "|" }' $f > output.unl
if [[ -f $FILES ]];
then if [[ $? -eq 0 ]]; then
echo "File successfully"
else
echo "File not successfully"
exit 1
fi
else
echo "Input file doesn't exists in directory" exit 1 fi
========================================================================
test1.sh
echo "Input file exists in directory"
test2.sh
echo "In test2 script"
./test.sh
echo "return code" $?
if [[ $? -eq 0 ]]; then
echo "inside"
./test1.sh
fi
test.shdoesn't appear to be properly formatted (see last line). Also, how is$FILESinitialized? Further, testing$?intest.shseems unnecessary since you're already testing for the existence of$FILESusing-f.test.shis syntactically invalid - thenawkprogram is missing a closing single quote and the last line won't work unless you put at leastfion a separate line. If you indeed haveexit 1on the same line as yourechostatement, then it would simply have become another output string, which would explain why the exit code is not set.$?. Instead of testing$?, just check the actual call. In other words, just writeif ./test.sh; then echo inside; ...; fiifunclosed and merely echoesexit 1rather than executing anexit?), so any answer is purely speculative, but I think perhaps yourexitis being called from within a subshell.