Error in Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in Shell script
# 8  
Old 10-27-2010
Not to me:
Code:
us99:/export/home/vbe $ bash -version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
us99:/export/home/vbe $ for n in {1..10}
> do
 $n % 2 ))
> out=$(( $n % 2 ))
> if [ $out -eq 0 ]
> then
> echo "$n is even number"

fi
done> else
> echo "$n is ODD number"
> fi
> done
1 is ODD number
2 is even number
3 is ODD number
4 is even number
5 is ODD number
6 is even number
7 is ODD number
8 is even number
9 is ODD number
10 is even number
us99:/export/home/vbe $ x=1
us99:/export/home/vbe $ while [ $x -le 5 ]
> do
> echo "Welcome $x times"
> x=$(( $x + 1 ))
> done
Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times
us99:/export/home/vbe $ COUNTER=20
us99:/export/home/vbe $ until [ $COUNTER -lt 10 ]
> do
> echo COUNTER $COUNTER
> let COUNTER-=1
> done
COUNTER 20
COUNTER 19
COUNTER 18
COUNTER 17
COUNTER 16
COUNTER 15
COUNTER 14
COUNTER 13
COUNTER 12
COUNTER 11
COUNTER 10

Have again a look at another shell you could use... the one you have is weird...

Regards
# 9  
Old 10-27-2010
Hmm, was the script edited on a Windows platform?

For one of the small scripts, please post the output from this sed enquiry which is designed to make MSDOS carriage-return characters visible:

For example:
Code:
sed -n l test2.prog

# 10  
Old 10-28-2010
Yes all these scripts are written in notepad on PC and then moved to unix directory via WInSCP. Here is the output and I can see \r$ after every line. It may be the culprit. Could you advise how to remove it?

Code:
x=1\r$
while [ $x -le 5 ]\r$
do\r$
  echo "Welcome $x times"\r$
  x=$(( $x + 1 ))\r$
done$

---------- Post updated at 05:18 AM ---------- Previous update was at 04:13 AM ----------

Thanks you for pointing out for MSDOS carriage-return characters issue.Infact this was the issue.I have fixed file for dos carriage-return by using this and it worked.

Code:
awk '{ sub("\r$", ""); print }' sourcefile > desctinationfile

Thanks a lot to both of you to point me in right direction.

Last edited by Scott; 10-28-2010 at 08:00 AM.. Reason: Use code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script with sql script error

Hi All when I execute from psql prompt, I get the result, when I try to automate using a shell script, the query is not working # `/usr/bin/psql -U postgres -d coba1 -c "select name from users where "Date" > current_date - 30;"` ERROR: column "Date" does not exist LINE 1: select... (2 Replies)
Discussion started by: srilinux09
2 Replies

2. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

3. Shell Programming and Scripting

Error in calling a shell script from another script

HI, We are using two shell scripts, script.sh,env.sh, where env.sh will be called inside script.sh. The variable inside env.sh is used as $var in script.sh.But while running the script its not identifying that variable. Is there any permission needed to call a script inside another script. ... (3 Replies)
Discussion started by: banupriyat
3 Replies

4. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

5. Shell Programming and Scripting

How to grep sql error in shell script and exit the script?

I need help in the following script. I want to grep the sql errors insert into the error table and exit the shell script if there is any error, otherwise keep running the scripts. Here is my script #!/bin/csh -f source .orapass set user = $USER set pass = $PASS cd /opt/data/scripts echo... (2 Replies)
Discussion started by: allinshell99
2 Replies

6. Shell Programming and Scripting

Shell script error

Hi, I have the following table in MYSQL: (the structure looks broken in this forum but if you copy/paste it into notepad, it'll look right): +----------------------------+-----------------------+------+-----+---------+----------------+ | Field | Type |... (0 Replies)
Discussion started by: tezarin
0 Replies

7. UNIX for Dummies Questions & Answers

Shell Script Error

Sorry typo found please ignore (0 Replies)
Discussion started by: jazz8146
0 Replies

8. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

9. UNIX for Dummies Questions & Answers

error in shell script

Hi, I have written a small shell script which logs into each oracle database on the server and displays whether it is in archivelog mode or not.. The script is as under: #!/bin/bash dblist=`ps -ef | grep smon | grep -v grep |cut -d'_' -f3` for ohome in $dblist; do sqlplus -s /nolog <<... (2 Replies)
Discussion started by: jalpan.pota
2 Replies
Login or Register to Ask a Question