If n>9 special syntax is needed. This example is snipped from my script which uses dcfldd to write image to pendrives: dcfldd if=$1 of=$2 of=$3 of=$4 of=$5 of=$6 of=$7 of=$8 of=$9 of=${10} of=${11} bs=64K status=on
$1 is the imagefile’s name, arguments 2 to 11 are the /dev/sdX names, where to flash the image. Note the ${10}, which is not $10, as it could be expected.
Hi, I tried to answer the question of your exercise 1: can I ask you a help in making the code cleaner?
#!/bin/bash
arguments=$@ #transforming the arguments in an array:
IFS=’ ’ read -r -a argumentsArr <<< $arguments
length=$#
i=$length
while [ $i -ge 0 ]
do
echo ${argumentsArr[$i]}
((i=i-1))
done
Also, why isn’t this working: ?
#!/bin/bash #transforming the arguments in an array:
IFS=’ ’ read -r -a argumentsArr <<< $@
length=$#
while [ $length -ge 0 ]
do
echo ${argumentsArr[$length]}
((length=length-1))
done