Results 1 to 10 of 12
Hey guys
I am just trying a simple script to run a statement in shell.. what is wrong with this code ?
Code:
#!/bin/sh
$count = 2
echo $1
if ...
- 12-10-2009 #1Just Joined!
- Join Date
- Sep 2007
- Posts
- 6
N00b help for scripting..
Hey guys
I am just trying a simple script to run a statement in shell.. what is wrong with this code ?
the runscript is basically a script in the directory.. and i want the output to always be appended into a file called scriptout..Code:#!/bin/sh $count = 2 echo $1 if [ $count <= $1 ]; then runscript $count >> scriptout $count++ fi
please help
- 12-10-2009 #2
Hi,
You have some issues here.
It looks like you came from a Perl world.
1) you do not need the dollar sign when you declare count
2) you have to remove the spaces around the equal sign when you assign
3) you have to replace the less or equal sign as follows
4) to increment count you have to put it in double parenthesis.
After correction it would look like this
Code:#!/bin/sh count=2 echo $1 if [ $count -le $1 ]; then runscript $count >> scriptout ((count++)) fiLinux and me it's a love story
- 12-10-2009 #3Just Joined!
- Join Date
- Sep 2007
- Posts
- 6
- 12-10-2009 #4
Yes. A dollar sign problem.
below would work
Code:#!/bin/sh echo 'Please Enter Number of Days:' read numb echo 'Please Enter Email address:' read email count=2 if [ $count -le $numb ]; then script $count $email >> scriptout ((count++)) fiLinux and me it's a love story
- 12-10-2009 #5Just Joined!
- Join Date
- Sep 2007
- Posts
- 6
- 12-10-2009 #6
Did you replace
byCode:script $count $email >> scriptout
?Code:./myscript $count $email >> scriptout
If that is the case then on the command line can you run and see what happens?
Code:./myscript $count $email >> scriptout
Linux and me it's a love story
- 12-10-2009 #7Just Joined!
- Join Date
- Sep 2007
- Posts
- 6
nono
thats the output error i get
nothing is changed the script is the same given on top..
just that i relized it should be a loop so i changed
if [ ]; then
fi
TO
while [];
do
done
rest all is same..
the error i get is at the end of each loop
/myscript: 2++: not found
myscript is the name of the above script
the script is
also the count++ is not increasing.. so the echo output is always DAY 2 and looping into that..Code:#!/bin/sh echo 'Please Enter Number of Days:' read numb echo 'Please Enter Email address:' read email count=2 while [ $count -le $numb ]; do echo "DAY $count" >> scriptout mailscript $count $email >> scriptout (($count++)) done
- 12-10-2009 #8
Can you post the full new script(after you changed if-then to while-do)?
When I saw your script I thought that you wanted to give it as an example and replace
withCode:script $count $email >> output
because script is a program that already exists in Linux. You can check it as followsCode:your_own_script $count $email >> output
Code:man script
Linux and me it's a love story
- 12-10-2009 #9Just Joined!
- Join Date
- Sep 2007
- Posts
- 6
I have posted the full script above
i think the problem is that it is not doing (($count++))
so it spits out error 2++ as 2 is the initial value
so therefore loop is infinite as count is not moving ahead..
- 12-10-2009 #10
Sorry I did not see the full script.
Yes the problem is
Replace it withCode:(($count++))
.Code:((count++))
If you look closely I did not use the dollar sign when incrementing in my above postsLinux and me it's a love story


Reply With Quote
