Slicing down bash arguments as you want
echo "arg length:" $#
for i in "${@:1:1}"
do
echo "$i"
done
for i in "${@:1}"
do
echo "$i"
done
echo " This is the last arg of cmd-args: "
echo "${@:$#:1}"
echo " args but not last one"
#shift
for i in "${@:1:$(expr $# - 1 )}"
do
echo "$i"
done
# Suggestion by Kevin: https://plus.google.com/106297454560345286689
# ${@:1:$# - 1} instead of ${@:1:$(expr $# - 1 )}
for i in "${@:1:$# - 1}"
do
echo "$i"
done