diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-09 17:15:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-09 17:20:10 +1200 |
commit | 9fb350dc7c8cc5259ef24e0cb097031179fab1d6 (patch) | |
tree | 839dd0b8ee3f5323b1cd6aefa22b605b99437d62 /bin/igex | |
parent | Mention nosls/sls flags in slsf(1) man page (diff) | |
download | dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.tar.gz dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.zip |
Improve commenting/exit handling in binscripts
Diffstat (limited to 'bin/igex')
-rwxr-xr-x | bin/igex | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -1,12 +1,34 @@ #!/bin/sh -# Run a command and ignore specified exit values. +# Run a command and ignore specified exit values + +# There should be at least two arguments +if [ "$#" -eq 0 ] ; then + printf >&2 'igs: Need an ignore list x,y,z and a command\n'; +fi + +# The list of values to ignore is the first argument; add a trailing comma for +# ease of parsing; shift it off igs=$1, shift + +# Run the command in the remaining arguments and grab its exit value "$@" ex=$? + +# Iterate through the ignored exit values by chopping its variable and checking +# each value until it's empty while [ -n "$igs" ] ; do + + # Get the first exit value in the remaining list ig=${igs%%,*} + + # If it matches the command's exit value, exit with 0 [ "$((ig == ex))" -eq 1 ] && exit 0 + + # Chop it off the list for the next iteration igs=${igs#*,} done + +# If we got right through the list, we exit with the same value as the command; +# i.e. we are not ignoring the value exit "$ex" |