why my code does not work?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers why my code does not work?
# 1  
Old 08-05-2012
why my code does not work?

Hi there
can anyone help me why my code is saying Badly placed ()'s.
Code:
#!/bin/csh
if ($#argv != 1) then
echo "One file is required"
exit 1
else
set lines=(`grep '404' $1 | cut -d" " -f5`)
foreach line ($lines)
printf ("Abnormal sites: %s\n", $line)
endif

thanks in advance! Smilie
# 2  
Old 08-05-2012
Sigh....

Please, STOP USING C-shell while you still can!

C-shell (csh) is considered outdated, very buggy, unreliable and generally to be avoided. Read this in-depth article instead of taking my word for it.

You might want to consider getting a book on shell programming. I suggest "KornShell Programming Tutorial" (Korn shell 88) or the "Hands-On KornShell93 Programming" (Korn shell 93), both by Barry Rosenberg. Both are phantastic reads, humorous writing along with excellent coverage of the subject.

I hope this helps.

bakunin

PS: there is even a logical flaw in your script: even if your number of arguments is correct you are not guaranteed that the user provided a valid file name. You will have to test if the file exists and is readable (use test -r <filename> for this) before piping it through grep or any other utility.
This User Gave Thanks to bakunin For This Post:
# 3  
Old 08-05-2012
Quote:
Originally Posted by bakunin
Sigh....

Please, STOP USING C-shell while you still can!

C-shell (csh) is considered outdated, very buggy, unreliable and generally to be avoided. Read this in-depth article instead of taking my word for it.

You might want to consider getting a book on shell programming. I suggest "KornShell Programming Tutorial" (Korn shell 88) or the "Hands-On KornShell93 Programming" (Korn shell 93), both by Barry Rosenberg. Both are phantastic reads, humorous writing along with excellent coverage of the subject.

I hope this helps.

bakunin

PS: there is even a logical flaw in your script: even if your number of arguments is correct you are not guaranteed that the user provided a valid file name. You will have to test if the file exists and is readable (use test -r <filename> for this) before piping it through grep or any other utility.
LOL I would like to but it is a task to write it in C shell
# 4  
Old 08-05-2012
Code:
lines=(`grep '404' $1 | cut -d" " -f5`)


Remove the brackets.
This User Gave Thanks to aashish.sharma8 For This Post:
# 5  
Old 08-05-2012
Quote:
Originally Posted by FUTURE_EINSTEIN
LOL I would like to but it is a task to write it in C shell
Ahem, ..., i can't imagine a production environment where csh is required these days. Even SAP on AIX have their system users use ksh as shell nowadays and they have probably been the last ones to switch over.

Is this some homework or classwork, i have to ask, therefore? If so, there is a special board for this, where you will be helped. If this is not homework i strongly suggest you inform your managers to have that (outright silly and dangerous) requirement changed instead of supporting such nonsense.

I outright denied any requests to write csh code in the last 5 years and made exceptions only for said SAP-on-AIX combination mentioned above for the ten years before. My career hasn't suffered one bit because of this.

bakunin
# 6  
Old 08-05-2012
Quote:
Originally Posted by bakunin
Ahem, ..., i can't imagine a production environment where csh is required these days. Even SAP on AIX have their system users use ksh as shell nowadays and they have probably been the last ones to switch over.

Is this some homework or classwork, i have to ask, therefore? If so, there is a special board for this, where you will be helped. If this is not homework i strongly suggest you inform your managers to have that (outright silly and dangerous) requirement changed instead of supporting such nonsense.

I outright denied any requests to write csh code in the last 5 years and made exceptions only for said SAP-on-AIX combination mentioned above for the ten years before. My career hasn't suffered one bit because of this.

bakunin
Thanks a lot but why in some cases it perfectly accepts it with brackets for e.g for
Code:
task=(`ls`)

---------- Post updated at 12:05 PM ---------- Previous update was at 12:01 PM ----------

Quote:
Originally Posted by agama
So this is homework???? Not to backseat-mod here, but if it is, there are rules to be followed on this forum when it comes to posting questions related to homework.

https://www.unix.com/homework-coursew...se-number.html
Home work in summer??? It is not a home work I am just learning system administration by myself and I don't understand csh at all however, at my work we are required to work with it. Smilie
# 7  
Old 08-05-2012
Quote:
Originally Posted by bakunin
Ahem, ..., i can't imagine a production environment where csh is required these days.
I blame alien mind control for the continued use of this obsolete, flawed, and obnoxious shell despite all alternatives and good sense, but it still happens. We get far too many requests here to hope otherwise. It seems to be a BSD thing.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. IP Networking

Discussion at work, would a router work pluging a cable in wan1 and lan1?

hi all. and sorry for the random question, but this sparkled a raging flame-war at work and i want more points of view situation a router, with linux of some sort, dhcp client requesting for ip in wan1 (as usual with wan ports) dhcp server listening in lan1, and assigning ip (as usual... (9 Replies)
Discussion started by: broli
9 Replies

2. Shell Programming and Scripting

My code worked on a Mac, now it does not work in another computer

I guess Mac has default bash. Then I copy my code to another comp and run it...And it gives me an error like "bad substitution".... How I can change my code??? Never had before this kind of situation. Help please. if then n=$(sort /Users/Natalie/lastserial | tail -1) ... (6 Replies)
Discussion started by: Natalie
6 Replies

3. Programming

Breakpoints dont work in Codeblocks, code does not build

Hey so I've written a program and it crashes every time I run it. I tried placing breakpoints to see what was going but to my surprise they do not work! I've placed them anywhere and they do not stop the execution of the program. In fact if I add code and hit rebuild it doesn't even build that... (1 Reply)
Discussion started by: Cambria
1 Replies

4. Shell Programming and Scripting

My script work on Linux but not work in sunos.

My script work on Linux but not work in sun os. my script. logFiles="sentLog1.log sentLog2.log" intial_time="0 0" logLocation="/usr/local/tomcat/logs/" sleepTime=600 failMessage=":: $(tput bold)Log not update$(tput rmso) = " successMessage="OK" arr=($logFiles)... (7 Replies)
Discussion started by: ooilinlove
7 Replies

5. IP Networking

NIC will not work, but it did work.

I have a client machine that was built and loaded with SCO UNIX 2.1.3, (yes it is old). The machine worked fine on the closed network that I tested on in my shop. I then had to change it to the network that it would be connected to. Below is the host file, router and subnet mask file that I usually... (0 Replies)
Discussion started by: NC user
0 Replies

6. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

7. UNIX for Dummies Questions & Answers

can't get this code to work

Ok I have just started using UNIX and am trying to write a script that will ping a list that I have created in a file called ipaddesses I need to get it to find the ip address that is not in use and do nothing however if it finds that all ip addresses have been taken to send me an e-mail! the... (13 Replies)
Discussion started by: jono
13 Replies

8. Programming

why the code cant work?

I'am new in C programming in UNIX. the code is as following: --------------------------------- #include<stdio.h> #include<unistd.h> int main() { printf("pid=%d\n",getpid()); return 0; } ---------------------------------- when I compile it(gcc) it output errors: Undefined ... (4 Replies)
Discussion started by: Namely
4 Replies
Login or Register to Ask a Question