run.sh: rewrite script to handle options more gracefully
authorBrian Norris <banorris@uci.edu>
Tue, 20 Nov 2012 00:39:36 +0000 (16:39 -0800)
committerBrian Norris <banorris@uci.edu>
Tue, 20 Nov 2012 00:39:36 +0000 (16:39 -0800)
Now you can do:

  ./run.sh [OPTIONS]

without having to specify a particular program (defaults to
./test/userprog.o).

run.sh

diff --git a/run.sh b/run.sh
index d4bf03000c92d6ab01f39b0e4cd14a17643f091f..c8dbeb46066c452d0c83260de684fdaf4e1eadf0 100755 (executable)
--- a/run.sh
+++ b/run.sh
@@ -2,8 +2,9 @@
 #
 # Runs a simple test (default: ./test/userprog.o)
 # Syntax:
-#  ./run.sh [gdb]
-#  ./run.sh [test program] [gdb]
+#  ./run.sh [test program] [OPTIONS]
+#  ./run.sh [OPTIONS]
+#  ./run.sh [gdb [test program]]
 #
 # If you include a 'gdb' argument, the your program will be launched with gdb.
 # You can also supply a test program argument to run something besides the
 #
 
 BIN=./test/userprog.o
+PREFIX=
 
 export LD_LIBRARY_PATH=.
 
-[ $# -gt 0 ] && [ "$1" != "gdb" ] && BIN=$1 && shift
+[ $# -gt 0 ] && [ "$1" = "gdb" ] && PREFIX=gdb && shift
+[ $# -gt 0 ] && [ -x "$1" ] && [ -f "$1" ] && BIN="$1" && shift
 
-if [ $# -gt 0 ] && [ "$1" = "gdb" ]; then
-       shift
-       gdb $BIN $@
-fi
-
-$BIN $@
+$PREFIX $BIN $@