I'm writing a bash script which will input arguments, the command would look like this:
command -a -b -c file -d -e
I would like to detect a specific argument (-b) with its specific location ($1, $2, $3)
#! /bin/bash
counter=0
while [ counter -lt $# ]
do
if [ $($counter) == "-b" ]
then
found=$counter
fi
let counter+=1
done
The problem rises in $($counter)
. Is there a way to use $counter
to call the value of an argument? For instance if counter=2
, I would like to call the value of argument $2
. $($counter)
doesn't work.