I am trying to create a shell script that takes a partial file name as its input and then does operations on the files with the matching names. For example, I have three files sample1.txt,sample2.txt and sample3.txt and this is my script
#!bin/bash
VALUE=$1
VALUE2=$2
FILE_NAME=$3
echo $FILE_NAME
And I run it with this command
sh myscript.sh arg1 arg2 sample*
But I get this as the output
sample3.txt (sample2.txt)
But what I want is
sample1.txt
sample2.txt
sample3.txt
How could I do this?
sample*could be any number of files). So use an array (list) at the receiver to get all the arguments ("$@") and not just the firstFILE_NAME=("$@")and print the whole array i.e.printf '%s\n' "${FILE_NAME[@]}"shiftcommand to shift the positional arguments. In your case to skip two arguments doshift 2; FILE_NAME=("$@")