Base aritmetic in bash

Viewed 37

I have a question. I wanted to count a number of parameters in a expression for a range.

Existing for now code part:

if [ -n "$@" ]; then
    name=$1

    # count=$(( $#-1 ))

    for a in [2..${count}]; do
        # some code
    done
fi

My questtion is, if there would be any difference in between this two ones:

$#-1

and

1-$#

?

Thanks

1 Answers

It seems like you want to iterate over the arguments starting from $2; in bash you can do it like this

#!/bin/bash

for a in "${@:2}"
do
    echo "$a"
done
Related