The examples have been run on a Raspberry Pi 3 running the 2017-04-10 version of Raspbian Jessie updated to early June 2017. Bash is at version 4.3.30(1).
While experimenting with some code recently, I found that the contents of a bash array were being executed. Fortunately they were not dangerous!
Here's a simple function:
#!/bin/bash
echo "y.sh starting"
echo "parameter string is <$@>"
args=( $@ )
echo "args array is <${args[@]}>"
echo "args array length is ${#args[@]}"
echo "y.sh ending"
and here is the output
pi@brassica:~ $ ./y.sh
y.sh starting
parameter string is <>
args array is <>
args array length is 0
y.sh ending
pi@brassica:~ $ ./y.sh ls
y.sh starting
parameter string is <ls>
args array is <ls>
args array length is 1
y.sh ending
Nothing unexpected above here.
After adding the y* parameter, the ls command output appears in the array:
pi@brassica:~ $ ./y.sh ls y*
y.sh starting
parameter string is <ls y01.sh y02.sh y03.sh y04a.sh y04.sh y.sh ytq>
args array is <ls y01.sh y02.sh y03.sh y04a.sh y04.sh y.sh ytq>
args array length is 8
y.sh ending
but when -la is added, there's no sign of the extra information
pi@brassica:~ $ ./y.sh ls -la y*
y.sh starting
parameter string is <ls -la y01.sh y02.sh y03.sh y04a.sh y04.sh y.sh ytq>
args array is <ls -la y01.sh y02.sh y03.sh y04a.sh y04.sh y.sh ytq>
args array length is 9
y.sh ending
It would be very helpful if someone could explain both why the command is being executed and what changes can be made so that it won't be executed. An explanation of why the "long" output from ls is not produced would also be of interest.
With thanks from the home of the Cheshire Cat.