-1

I have the follow files in my folder:

a.jpg b.jpg c.jpg

And I have the follow script:

#!/bin/bash
echo $1

If I run:

script.sh $(ls)

My output is:

a.jpg

But I want to be:

a.jpg b.jpg c.jpg

So, Why doesn't echo prints all the output from ls?

Magenta
  • 21

1 Answers1

1

In your script, you explicitly ask to echo only the first argument:

echo $1

If you would ask for the second argument

echo $2

you'd get b.jpg as output.

You can get all the files using echo $* or echo "$@".

Another option is that you make sure that the complete output of ls is packed in the first argument. You can do that by adding quotes around it.

script.sh "$(ls)"
Chris Davies
  • 4,560
Ljm Dullaart
  • 2,788