Error with while loop

the program just prints all the command line arguments

Getting error in the program
error

./hellow: line 13: 0: command not found
./hellow: line 13: 0: command not found

below is the program

#!/bin/bash
num=$#
echo $num
if [ $# -eq 0 ]
then
    echo "No arguments are passed ."
else
  echo "total no of arguments are  $0 are $#"
fi
echo "####### starting the program"
string=hellow
i=0
while [[ `$num` > `$i` ]]
do
echo "$"$i
string=$string$$string1
(( i+=1 ))
done
echo " #### and the results are #####"
echo string= $string
echo string1 = $string1

What it is complaining about is the use of back ticks ( ` ), which should be left out.

1 Like

no not a problem with the ` i do think the OS is unable to find the " while " program
Any idea whether iam missing some header file like that because i am new to the shell programming i am asking this :wall:

The problem is with the backticks, ` . As you're new to shell scripting, perhaps you should listen to someone with more than 5700 posts?

As Scrutinizer rightly said, remove the back-ticks on line 13..

With those back-ticks, your shell is assuming that the values of num and i are commands...

1 Like

As per your recommendatio i used

while [ $num > $i ] 

instead of using

while [[ `$num` > `$i` ]]

still facing the same problem

./hellow: line 13: [0: command not found

No-one mentioned using single [ ... ], and I suspect you missed a space between [ and $num. Please use code tags, when posting code.

Use:

[[ $num > $i ]]

Or:

[ "$num" -gt "$i" ]
1 Like

now that makes sense :slight_smile: thanks a lot scott it works thanks Scrutinizer