Bash aliases support arguments
authorFrederic Massart <fred@moodle.com>
Thu, 21 Feb 2013 09:05:48 +0000 (17:05 +0800)
committerFrederic Massart <fred@moodle.com>
Thu, 21 Feb 2013 09:05:48 +0000 (17:05 +0800)
moodle

diff --git a/moodle b/moodle
index c33c314..130f627 100755 (executable)
--- a/moodle
+++ b/moodle
@@ -53,9 +53,14 @@ ALIAS=`$BIN show $COMMAND`
 
 if [ -n "$ALIAS" ]
 then
-    # It's a shell command.
+    # It's a shell command. Let's substitute the arguments.
     if [[ ${ALIAS:0:1} == '!' ]]; then
-        ${ALIAS:1}
+        CMD="${ALIAS:1}"
+        for ((I = 2; I <= $#; I++)); do
+            ARG=${@:I:1}
+            CMD=${CMD//\$$((I-1))/$ARG}
+        done
+        $CMD
         exit $?
     fi
     # If we're here, it's not a shell command. Let's parse the command and arguments.