Skip to content

Commit

Permalink
scripts/qemustart: more portable array operation
Browse files Browse the repository at this point in the history
The following commands output 1,2,1,1

    cmd0='a=("${a[@]}" 'a'); echo "${#a}"'
    cmd1='a+=('a'); echo "${#a}"'
    bash -c "$cmd0"; zsh -c "$cmd0"
    bash -c "$cmd1"; zsh -c "$cmd1"

The following outputs 0,1,0,0

    cmd2='f() { echo "$#"; }; f "${a[@]}"'
    cmd3="a=(); $cmd2"
    bash -c "$cmd2"; zsh -c "$cmd2"
    bash -c "$cmd3"; zsh -c "$cmd3"

Signed-off-by: Yousong Zhou <[email protected]>
  • Loading branch information
yousong committed Jan 31, 2018
1 parent c9c2e4d commit aa66aa0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scripts/qemustart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ rand_mac() {
}

parse_args() {
o_qemu_extra=()
while [ "$#" -gt 0 ]; do
case "$1" in
--kernel) o_kernel="$2"; shift 2 ;;
Expand All @@ -131,7 +132,7 @@ parse_args() {
elif [ -z "$o_subtarget" ]; then
o_subtarget="$1"
else
o_qemu_extra=("${o_qemu_extra[@]}" "$1")
o_qemu_extra+=("$1")
fi
shift
;;
Expand Down Expand Up @@ -174,11 +175,10 @@ start_qemu_armvirt() {
if [ ! -f "$rootfs" -a -s "$rootfs.gz" ]; then
gunzip "$rootfs.gz"
fi
o_qemu_extra=( \
o_qemu_extra+=( \
"-drive" "file=$rootfs,format=raw,if=virtio" \
"-append" "root=/dev/vda rootwait" \
"${o_qemu_extra[@]}" \
)
)
}

"$qemu_exe" -machine virt -cpu "$cpu" -nographic \
Expand Down

0 comments on commit aa66aa0

Please sign in to comment.