Bash Input re-direction gives standard input into the command instead of parameter / filename? Bash Input re-direction gives standard input into the command instead of parameter / filename? shell shell

Bash Input re-direction gives standard input into the command instead of parameter / filename?


ls does not read its arguments from standard input, but from the command line.

You could simply do:

ls -l $(cat com)


Simply try this:

ls $(<com)

/bin/ls, like many other standard un*x commands, work with command line arguments, not with STDIN.

You could write:

ls $(cat com)

do permit syntax: $(< filename) and work quicker than $(cat ...) or cat com because work as builtin (no fork).

Using STDIN for passing arguments

There is a command xargs for doing this:

xargs /bin/ls <com

But this won't work with wildcard (*).

echo $(<com) | xargs ls


As far as I understand, the shell will take the input Chapter* from the file "com" and place it next to ls

No, that's not what it means.

ls < com

is equivalent to

cat com | ls

Since ls doesn't read it's standard input, the data from com is ignored. The behavior you're describing is achieved, as another answer mentioned, by using:

ls $(<com)