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

I have a file /u/setuplink.txt

 
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

#!/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

ln: cannot create tnohup.sh: File exists

Can you please suggest ?

Check if the destination exists before you make the link!
With a function

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
1 Like

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