I am new to bash scripting and trying to learn a few things. Here is the code I have tried:
n=$1
shift
echo "Printing your name $n times"
count=1
for ((i=1;i<=$n;i++))
do
echo $@ -$i
count='expr[$count+1]'
done
echo 'New Model'
count=1
while ["$count" -le "$n"]
do
echo $@ -$i
count='expr[$count+1]'
done
The for loop works fine, but the while loop is not printing the desired result. the Result of the for loop and while should be the same. Could you please tell me where I have gone wrong. Thank you.
One problem is that you need spaces around the brackets, so that
bashknows that they’re separate words. That is, change this:to this:
Another is that this:
actually sets the variable
countto the specific stringexpr[$count+1]. What you seem to mean is this:which increases the value of
countby 1.