diff options
author | David 'Digit' Turner <digit@google.com> | 2011-10-27 14:43:25 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@google.com> | 2011-11-24 14:55:21 +0100 |
commit | ec2b8ddacdadf4c04325dfd0a4135566ec29a8ef (patch) | |
tree | 91926caf364ec05aa61d332b7c59eaec49a3a796 /ndk-gdb | |
parent | f8307ae562e727e36df2532f0a67d7a0fd65c84e (diff) | |
download | ndk-ec2b8ddacdadf4c04325dfd0a4135566ec29a8ef.tar.gz |
Fix the use of $@ in all shell scripts
This patch allows all our development scripts, as well as ndk-gdb
to work well when parameters containing spaces are used.
The $@ shell variable is very special because it will expand
differently if inside a quoted string. What this means is that,
while $@ normally corresponds to the list of all parameters to
a function or script, we have:
$@ -> expands to a single string
"$@" -> expands to a series of strings
This is important when using them as parameters to other commands
for example consider:
# Simple function to dump all parameters, one per line.
dump () {
for ITEM; do
echo "$ITEM"
done
}
dump1 () { # this will always print a single line
dump $@
}
dump2 () { # this will print one line per item
dump "$@"
}
dump1 aaa bbb ccc # prints "aaa bbb ccc" on a single line
dump2 aaa bbb ccc # prints three lines: "aaa", "bbb" and "ccc"
Generally speaking, one should always use "$@" except in very rare cases
(e.g. when called from an eval command).
Change-Id: I87ec2a7b078cbe463f0ec0257ecad8fd38835b2e
Diffstat (limited to 'ndk-gdb')
-rwxr-xr-x | ndk-gdb | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -304,9 +304,9 @@ _adb_var_shell () # Run the command, while storing the standard output to CMD_OUT # and appending the exit code as the last line. if [ "$REDIRECT_STDERR" != 0 ]; then - $ADB_CMD shell $@ ";" echo \$? | sed -e 's![[:cntrl:]]!!g' > $CMD_OUT 2>&1 + $ADB_CMD shell "$@" ";" echo \$? | sed -e 's![[:cntrl:]]!!g' > $CMD_OUT 2>&1 else - $ADB_CMD shell $@ ";" echo \$? | sed -e 's![[:cntrl:]]!!g' > $CMD_OUT + $ADB_CMD shell "$@" ";" echo \$? | sed -e 's![[:cntrl:]]!!g' > $CMD_OUT fi # Get last line in log, which contains the exit code from the command RET=`sed -e '$!d' $CMD_OUT` @@ -330,14 +330,14 @@ _adb_var_shell () # or 1 (failure) otherwise. adb_var_shell () { - _adb_var_shell 0 $@ + _adb_var_shell 0 "$@" } # A variant of adb_var_shell that stores both stdout and stderr in the output # $1: Variable name adb_var_shell2 () { - _adb_var_shell 1 $@ + _adb_var_shell 1 "$@" } # Return the PID of a given package or program, or 0 if it doesn't run |