Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Your problem is using sh -c "...", see @Gilles's answer@Gilles's answer for more details.

Further more, sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implicationInvoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@$@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done

Your problem is using sh -c "...", see @Gilles's answer for more details.

Further more, sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done

Your problem is using sh -c "...", see @Gilles's answer for more details.

Further more, sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done
added 137 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

Your problem is using sh -c "...", see @Gilles's answer for more details.

Further more, sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done

sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done

Your problem is using sh -c "...", see @Gilles's answer for more details.

Further more, sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done
Code typo
Source Link
Chris Davies
  • 128k
  • 16
  • 178
  • 323

sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c "'arr='arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done

sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c "'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done

sh (refer to POSIX sh) does not support array (strictly speaking, it has only one array, $@), you need to call other shells on your system, which support array like bash, zsh or ksh.

bash -c 'arr=(1 2 3 4 5);for var in "${arr[@]}";do echo "$var"; done'

Also note that you have a mistake when leaving ${arr[@]} un-quote, actually you need for var in "${arr[@]}" instead. Invoking variable without quotes calling split+glob and is source of many security implication.

To play with POSIX sh, you can use $@:

set -- 1 2 3 4 5
for var do
  printf '%s\n' "$var"
done
added 58 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419
Loading
Post Migrated Here from serverfault.com (revisions)
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419
Loading