I would like my bash script to take either 2 or 3 arguments with the last argument always being the input file to open. So the index of argument should depend on how many arguments provided. I know this can be realized by if statement, like:
if [ $# -eq 3 ]; then
INFILE=$3
elif [ $# -eq 2 ]; then
INFILE=$2
fi
..open file to read...
However I was hoping this to be done by a one liner which would look like this:
INFILE=$($#)
It does not work though. Same thing with INFILE=$"$#". Is it possible to specify index of argument directly with "$#"