Condition loop.
Hi,
i am checking for a file sha.txt if not found then it will execute ./scr1 else it will exit. i tried below elif statement to try if ./scr1 script gives error it should exit not execute below commands. But i am unsuccessful. Please help. Code:
cd $HOME |
if/elif/else are all at the same level. You want to nest an if statement, to check something that happens in the first if.
Also, $# is the number of positional parameters, you seem to want $?, last command's return code. Code:
if [ ! -f sha.txt ]; then |
Quote:
Code:
cd $HOME |
Quote:
Code:
cd $HOME |
i tried all permutation.. what i am getting is, in ./scr1 script i just wrote echo " Here everything is fine" all the conditions were running fine. But when i changed that script (scr1) as eho "Here everything is fine" ie., instead of "echo" i wrote "eho" but still elif condition is true elif [ 0 -eq 0 ] and all other below commans ran. ?
Code:
[prompt] sh -x sha.sh |
Quote:
Quote:
http://tldp.org/LDP/abs/html/ Lots of examples and advice. |
TB0ne,
This is just a testing, i am going to implement after i am successful. So ./scr1 for now is no problem. Quote:
Code:
echo " The output is correct" |
Quote:
Read your script, and think about what it's doing. You're checking for file sha.txt, and if it's not found, it runs scr1, with an elif. And did you read/follow the advice given to you by jhwilliams??? |
yes, i changed it to $? according to hime.
i am very new to shell scripting trying to explore myself. i will just try to explain what i want. if sha.txt is not there then it will run scr1, in scr1 there are certain simple commands are there if it fails i am trying to catch up that thing in elif condition and trying to stop other command to run after elfi. Hope i made it clear. |
Quote:
You state your problem...would seem to make sense that you'd just put an echo statement in your script, to see what the return code of scr1 actually IS, so you can diagnose your problem from there. Also, just perform that ONE step, alone, by itself, until you get it to work...THEN add in more logic, so that you know where the problem(s) are as you go. |
i tried and did it myself....
it was that i have start one if statment in src1 only not out side. Code:
eho "every thing is fine here" Code:
cd $HOME |
All times are GMT -5. The time now is 03:26 AM. |