I read a similar example from bash programming book:
$ cat indirection
#!/usr/bin/env bash
set -x
num=1
eval "${!num#*:}"
$
When I execute the script with bash indirection "test:echo blah"
, then how is the last line of the script processed? I guess first the indirection happens so that eval "${!num#*:}"
becomes eval "${1#*:}"
? Then substring removal takes place and eval "${1#*:}"
becomes eval echo blah
? If yes, then why is eval
needed, i.e ${!num#*:}
instead of eval "${!num#*:}"
would provide the same results?
num=1
is in factnum=$1
according to your execute string. – Jul 06 '17 at 02:31