I have a script with multiple command line parameters and I'd like to use one of them in a for loop. Here is a simplified version:
while getopts s:p: flag
do
case "${flag}" in
s) samples=${OPTARG};;
p) parameter=${OPTARG};;
esac
done
for sample in $samples
do
echo "$sample" echo "$parameter"
done
When I run bash script.sh -s Sample1 Sample2 Sample3 -p test I get:
Sample1 echo
But what I would like to get is:
Sample1 test
Sample2 test
Sample3 test
How would I go about this? I only see info for iterating through all the command line parameters using $@ but I don't know how to iterate through a specific command line parameter. Thanks in advance!
bash script.sh -p test Sample1 Sample2 Sample3), and use"$@"to iterate over them?