The script below prints positional parameters. The idea is to skip some optional arguments (where the number of optional args is given by SKIP
), and then get the last two arguments. For the last arg, for example, I use an arithmetic expansion to get V2
, and then indirect expansion of V2
to get A2
. Running test a b c
, for example, prints b
and c
.
Question: the two-step expansion is clunky. Is there a one-liner that will derive the value of a given arg?
#!/bin/bash
SKIP=1
# get second-from-last arg
V1=$(( SKIP+1 ))
A1=${!V1}
# get last arg
V2=$(( SKIP+2 ))
A2=${!V2}
echo A1 is $A1
echo A2 is $A2