0

I have a bash script called TestList and I want it to take the argument Small/*.c

Small is a directory and it contains files:

bar.c bar.h foo.c foo.h main.c

The goal is to get Small and *.c as seperate strings in my bash script but whenever I try to do this *.c always becomes bar.c

for example:

echo  `ls Small/*.c``

outputs: Small/bar.c Small/foo.c Small/main.c

echo  `ls $1``

outputs: Small/bar.c

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
PresB4Me
  • 17
  • 5
  • 1
    please review [how to create a minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and then come back and update the question; in particular, provide a copy of a shell script that demonstrates your issue, along with an example of how you're calling the shell script, plus the expected output – markp-fuso Oct 25 '20 at 19:46

1 Answers1

1

Mark your argument with quotes, so your call would be something like ./TestList "Small/*.c". This will yield the same output.

The reason why your command wasn't working as expected before is because * is a special character that needs to be escaped. Therefore, you can also supply Small/\*.c as an argument, without the quotes.

  • 1
    Note the "Answer Well-Asked Questions" section of [How to Answer](https://stackoverflow.com/help/how-to-answer), and the note therein regarding questions that "have been asked and answered many times before". – Charles Duffy Oct 25 '20 at 21:52