I have a small shell script and what I want to do when it is run is to display each N'th parameter entered by the user, where N is the first parameter.
Ex: for input 2 3 4 5 6
I should display 3 5
. What I have until now:
N=$1
for ((i=2;i<$#;i+=$N))
do
echo -n ${i}" "
done
However, I get a syntax error: operand expected at this part: i+=$N
.
How can I solve this? If I replace i+=$N
with, say, i+=2
, it works. But i want N there...
((i=i+$N))
i+=N
, without$
../script.sh 2 p1 p2 p3 p4 p5
, your script will print out2 4
.