Syntax error, puzzling


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax error, puzzling
# 1  
Old 04-21-2009
Syntax error, puzzling

I am just learning over here unix scripting and the OS in general.

I wrote this script (with some great help from you guys here) when I test at my desktop with cygwin it works fine, but when I take it to work and try it on the Solaris 2 system there I get an error on line 4 syntax error "fileArray". So I tried putting spaces in befor and after the = sign and I got a syntax error on line 4 character "(". This is all very puzzling to me. I would very grateful if someone could help.

I don't know if this is important, but my shell tool says on top it says it is tcsh.

Here is the full script:

Code:
#!/usr/bin/sh
echo "[CTO][GSR]/ /  /|ql|[CTE]
[DOWN]" > C:/Test/File
fileArray=($(find . -maxdepth 1 -name 'P*' -type f))
tLen=${#fileArray[@]}
echo "$tLen"
for (( i=1; i<${tLen}; i++ ));
do 
echo "[CTO][GSR]/ /  /|ql|[CTE]
[DOWN]" >> C:/Test/File
done
for file in /usr/tmp
do
    rm "$file"
done

# 2  
Old 04-21-2009
this looks like a 'bash' script - change
Code:
#!/usr/bin/sh

TO
Code:
#!/usr/bin/bash

# 3  
Old 04-21-2009
That's correct, I wrote this as a bash script, but when I tried running it today at work it wouldn't run, so I changed it to sh.

I thought that the syntax was very similar. I thought that bash just added some features to sh.
# 4  
Old 04-21-2009
Is there any way to edit this script so that it is compatible with sh?
# 5  
Old 04-22-2009
I think I might have this figured out:

Code:
#!/usr/bin/sh
echo -n > C:/Test/File
for file in P*
do 
echo "[CTO][GSR]/ /  /|ql|[CTE]
[DOWN]" >> C:/Test/File
done
cd usr/tmp
for file in *
do
    rm "$file"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

2. UNIX for Dummies Questions & Answers

Puzzling permission issue

I have a file, the long listing output by 'ls -l' is -rw-r--r-- 1 usera agroup 1246 Jul 7 14:44 temp.R The file is under a Solaris ZFS file system. As a different user (userb), I did cp temp.R /tmp ls -l /tmp/temp.R -rw-r--r-- 1 userb agroup 1246 Nov 16 14:45 /tmp/temp.R ... (14 Replies)
Discussion started by: nugulus
14 Replies

3. Shell Programming and Scripting

special grep on log files... puzzling me.

Okay, guys, I've got one: I've got a script that formats all of the messages in a log file. It works on a completely verbose method. I'm trying to write a filter that will search for a bunch of case-insensitive strings, but also, always print the first 2 lines. Here's the egrep part: ... (4 Replies)
Discussion started by: quirkasaurus
4 Replies

4. Programming

Linux System C headers puzzling

I am new to Linux system programming, and I found the sophisiticated definition of some library function differ a lot with what I learnt in classes. Here is the question: what does the suffix of function `chmod' in sys/stat.h mean. The funtion claimation is like following: extern int... (5 Replies)
Discussion started by: JackCrital2005
5 Replies

5. IP Networking

Puzzling Traceroute output

This is the output that I get every so often when trying to do a traceroute to the web server whenever it's inaccessible: traceroute to 64.40.98.181 (64.40.98.181), 30 hops max, 40 byte packets 1 207.97.207.194 (207.97.207.194) 2.625 ms 2.840 ms 2.968 ms 2 core1-5.iad1.rackspace.com... (6 Replies)
Discussion started by: gaspol
6 Replies

6. Shell Programming and Scripting

Puzzling Problem: Going back to the previous directory

Hi, I am trying to figure out if there is a way to make linux take me back to the previous directory I was working in. For instance, I am in /home/username/directory1 Then if I cd into /home/username/directory1/temp1/temp2/temp3 I would like to immediately go back to the previous... (2 Replies)
Discussion started by: Legend986
2 Replies

7. AIX

nim mksysb error :/usr/bin/savevg[33]: 1016,07: syntax error

-------------------------------------------------------------------------------- Hello, help me please. I am trying to create a mksysb bakup using nim. I am geting this error, how to correct it ? : Command : failed stdout: yes stderr: no... (9 Replies)
Discussion started by: astjen
9 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. Shell Programming and Scripting

puzzling regexp

hey guys, i'm having some problems with my understanding of this whole regexp thing. I'm just exploring here really by trying to do various match & filter & print stuff on the console. I figured i want to get the IP of an interface. So my idea here was that first i filter to extract only... (4 Replies)
Discussion started by: jad
4 Replies

10. Shell Programming and Scripting

AWk is still puzzling me...

Hi all. Here's what i want to do: my_first_file #!/usr/bin/ksh # BLA BLA BLA BLA printf "this is my first file \n" echo " I understand this far" printf "the day's over \n" echo "great" my_second_file #!/usr/bin/ksh # BLA BLA BLA BLA printf "this is my first file \n" AN_INSERTED_LINE... (2 Replies)
Discussion started by: penguin-friend
2 Replies
Login or Register to Ask a Question