how do you supply a literal asterisk * when specifying a filename to a command substitution in bash?
Consider the following directory:
host:/tmp/backtick-test# ls -l
total 0
-rw-r--r-- 1 root wheel 0 29 Jun 23:18 test
-rw-r--r-- 1 root wheel 0 29 Jun 23:18 test*
I can't work out how to specify the second file test* with $().
List both files:
host:/tmp/backtick-test# ls test*
test test*
List only the file with the trailing *:
host:/tmp/backtick-test# ls test\*
test*
Now with commmand expansion:
host:/tmp/backtick-test# echo $(ls test*)
test test test*
Returns three filenames.
/tmp/backtick-test# echo $(ls -al "test*")
-rw-r--r-- 1 root wheel 0 29 Jun 23:18 test test*
Better, returns two but I only want the second one.
$(ls -al "test*")may be just an example, but if you were thinking of using the output oflsto construct a command line, read this first: Don't Parse ls - in short, usefindinstead. Also look into using arrays to store any arguments you want to pass to programs, it avoids all issues with word-splitting. e.g.readarray -d '' -t myarray < <(find ... -print0)