I'm writing a bash script where I need to get the names of all the files that match a certain pattern I give as argument.For example if I have the files 'test1.txt', 'test2.txt' and 'test3.py' and run my command as :
my_command *.txt
I want to get the names 'test1.txt' and 'test2.txt' yet when I do this I only seem to get the one that is first alphabetically.
I'm sorry if this is an asked and answered question or a noobish one but I'm very new to bash scripting.
I've tried ls $1, echo $1, echo "$1"
and finally
for var in $1;
do echo $var
done
and all those methods have given me only the alphabetically first file
I suggest to replace
$1in your code with"$@"to get all arguments tomy_command.