Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 [ ! -f sha.txt ]; then
./scr1
elif [ $# -eq 0 ];then
echo " The output is correct"
echo " successfull"
else
echo "The file sha.txt is not found"
exit
fi
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 [ ! -f sha.txt ]; then
./scr1
elif [ $# -eq 0 ];then
echo " The output is correct"
echo " successfull"
else
echo "The file sha.txt is not found"
exit
fi
How about telling us what error(s) you're getting??? And again, as with your other threads, have you tried looking any scripting guides up, or trying some different permutations of this?
Code:
cd $HOME
if [ ! -f sha.txt ]
then
./scr1
elif [ $# -eq 0 ]
then
echo " The output is correct"
echo " successfull"
else
echo "The file sha.txt is not found"
exit
fi
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 [ ! -f sha.txt ]; then
./scr1
elif [ $# -eq 0 ];then
echo " The output is correct"
echo " successfull"
else
echo "The file sha.txt is not found"
exit
fi
How about telling us what error(s) you're getting??? And again, as with your other threads, have you tried looking any scripting guides up, or trying some different permutations of this?
Code:
cd $HOME
if [ ! -f sha.txt ]
then
./scr1
elif [ $# -eq 0 ]
then
echo " The output is correct"
echo " successfull"
else
echo "The file sha.txt is not found"
exit
fi
Hard-coding a filename into a script isn't a good thing to do, nor is calling the scr1 script from a "./" directory. Makes your scripts much more prone to failure, and harder to maintain.
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
+ date +%m%d
xdte=1125
dblist=amos mss
HOME=/usr/home
DBPATH=dbpath/path
+ cd /usr/home
+ [ ! -f sha.txt ]
+ [ 0 -eq 0 ]
+ echo The output is correct
The output is correct
+ echo successfull
successfull
[prompt] cat /usr/home/progress/log/scr1
eho "every thing is fine here"
No you didn't. What I posted above worked with no errors, and a minor change. That change I found on the first Google hit when searching for bash scripting examples to check if a file didn't exist.
Quote:
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. ?
So your problem is actually in the scr1 script, not what you posted? And amazingly, if you have errors in the script ("eho" instead of "echo"), the script won't work. Also, see previous statement about the very bad idea of using "./" to specify a path, and about hard-coding names into scripts. One of the MANY bash scripting tutorials you can find with a Google search is: http://tldp.org/LDP/abs/html/
This is just a testing, i am going to implement after i am successful. So ./scr1 for now is no problem.
Quote:
:
So your problem is actually in the scr1 script, not what you posted? And amazingly, if you have errors in the script ("eho" instead of "echo"), the script won't work.
exactly i want it to come out when some thing is wrong in the script "scr1". not executed other below commands
TB0ne,
This is just a testing, i am going to implement after i am successful. So ./scr1 for now is no problem.
exactly i want it to come out when some thing is wrong in the script "scr1". not executed other below commands
Code:
echo " The output is correct"
echo " successfull"
Again, you need to go through the bash scripting tutorial you've been directed to numerous times.
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???
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.
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.
Yes, we understand. Again, go through the scripting tutorials, because that's how you're going to learn. And again, THINK about what you're doing, what the result(s) you want are, then step-by-step, THINK about how to achieve them.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.