aboutsummaryrefslogtreecommitdiff
path: root/bin/igex.sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-04-05 20:06:39 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-04-05 20:46:47 +1200
commitc8ab406749124d2e762ad5cf53963070113afd0f (patch)
tree54c9721a06957ebe7098a211eea803b0230c0f5d /bin/igex.sh
parentHandle POSIX correctness in ~/.bash_profile (diff)
downloaddotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz
dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/igex.sh')
-rw-r--r--bin/igex.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/bin/igex.sh b/bin/igex.sh
new file mode 100644
index 00000000..09f1206f
--- /dev/null
+++ b/bin/igex.sh
@@ -0,0 +1,33 @@
+# 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"