Ignore exit status for #!/bin/bash -e


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignore exit status for #!/bin/bash -e
# 1  
Old 12-12-2016
Tools Ignore exit status for #!/bin/bash -e

I have a file /u/setuplink.txt

Code:
 
more setuplink.txt
  ln -s /u/force.sh stopf.sh
  ln -s /u/tnohup.sh tnohup.sh
  ln -s /u/quick.sh startquick.sh

more runstat.sh
Code:
#!/bin/bash -e
echo "START"
/u/setuplink.txt
echo "END"

i wish to exit the runstat.sh for any errors except if the link already exists.

So, i wish to exit for all errors except for this error
Code:
ln: cannot create tnohup.sh: File exists

Can you please suggest ?
# 2  
Old 12-12-2016
Check if the destination exists before you make the link!
With a function
Code:
ln_s(){
  [[ -e $1 ]] && return
  ln -s "$1" "$2"
}
ln_s /u/force.sh stopf.sh
ln_s /u/tnohup.sh tnohup.sh
ln_s /u/quick.sh startquick

This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 12-13-2016
I'm a little confused on the requirement:-
  1. Would you worry if a file or directory of that name already existed?
  2. Are you just trying to create symbolic links if the symbolic link does not exist?
Have a look at the options for flags for the test man test You can see that -e is just for "exists" but you can tailor it to look for directories, plain files, symbolic links, pipes, empty files etc. to suit your needs.


Does that help to tie down the possible conditions you need to handle?




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

3. Shell Programming and Scripting

Want to get the exit status

Hi All, I am trying to create a zip file with all the txt files(these are in large number) in the current directory. I am able to do this operation sucessfully. After this i want to get the status of the tar command executed and do accordingly. When i am trying with the below code, the status... (3 Replies)
Discussion started by: paddu
3 Replies

4. Shell Programming and Scripting

Exit Status

I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
Discussion started by: smkremer
2 Replies

5. Shell Programming and Scripting

Exit status redirection

Hi, I'm having this simple code below, the file serverlist has a list of IPs one per line. When executed the while loop is executed only once, after that the program terminates. How should i redirect the exit status, so that the entire list of IP will get executed? #!/bin/bash exec <... (4 Replies)
Discussion started by: agent001
4 Replies

6. Shell Programming and Scripting

Exit status

I'm preparing for exam and one of exams is to write own test command... I wonder if in unix is a command which just returns exit code you specify.. I know I can easily write a function like this: exStatus() { return $1 } -> my question is rather theoretical thank you! (9 Replies)
Discussion started by: MartyIX
9 Replies

7. Shell Programming and Scripting

How to get the exit status

Hi all, I'm running a program which return 1 upon success. But when encounters problem shell return 's '1' . How to differentiate between them the shell return value and script return value. Ex. function fn return '1' if executed successfully and '0' if failed. But when if shell encounters... (1 Reply)
Discussion started by: yhacks
1 Replies

8. Shell Programming and Scripting

exit status for isql

I'm trying to write a script that will update a table in sysbase. If it's failed then I want to rerun it one more time before exiting the script (fail due to bad value such as trying to put a string into datetime field or bad connection to the database) Well my code below will always return... (2 Replies)
Discussion started by: sirrtuan
2 Replies

9. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

10. Shell Programming and Scripting

exit status

i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127.. to what does a 127 exit status refer too and what is its purpose in the code. moxxx68 (1 Reply)
Discussion started by: moxxx68
1 Replies
Login or Register to Ask a Question