![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| switch login | sharif | UNIX for Advanced & Expert Users | 1 | 12-12-2007 01:03 AM |
| Switch | abey | High Level Programming | 12 | 06-27-2006 04:11 PM |
| switch from csh to ksh | veeracer | Shell Programming and Scripting | 8 | 11-05-2004 11:13 AM |
| switch from csh to ksh | veeracer | UNIX for Dummies Questions & Answers | 1 | 11-03-2004 03:28 PM |
| can you switch | neer45 | Shell Programming and Scripting | 3 | 12-05-2001 05:54 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
This script receive in input 2 parameters, the use $2 in this way: switch ($2) case r: p=r-- echo $2 ok breaksw case rw: p=rw- echo $2 ok breaksw case rwx: p=rwx echo $2 ok breaksw default echo Errore, secondo parametro errato #exit 0 endsw Why I have the error???: ./script: line 1: syntax error near unexpected token `$2' ./script: line 1: `switch ($2)' I followed this guide: switch ( str ) case string1: commandlist1 breaksw case string2: commandlist2 breaksw default commandlist endsw |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You should run this script using csh, And instead of u need to use set keywod before the assignment statement
|
|
#3
|
|||
|
|||
|
I wrote:
#! /bin/csh before the lines posted in my first post, and still give my the same error |
|
#4
|
||||
|
||||
|
Hi.
A few modifications: Code:
#!/usr/bin/env csh # @(#) s1 Demonstrate switch command. if ( $#argv < 2 ) then echo " Need 2 arguments." exit 1 endif echo echo "(Versions displayed with local utility version)" sh -c "version >/dev/null 2>&1" && version tcsh echo echo " Before end of switch." switch ($2) case r: set p=r-- echo $2 ok breaksw case rw: set p=rw- echo $2 ok breaksw case rwx: set p=rwx echo $2 ok breaksw default echo Errore, secondo parametro errato #exit 0 endsw echo " After switch." exit 0 Code:
% ./s1 any-string rw (Versions displayed with local utility version) tcsh 6.13.00 Before end of switch. rw ok After switch. ----- Standard advice: avoid csh family for scripting, use Bourne shell family. |
|
#5
|
|||
|
|||
|
Thank you very much, but the script still doen't work.
If I copy and paste your code on a text file, and I try to execute it, the shell give my this error: /usr/bin/env: csh: No such file or directory So I tryed to change the directory: *Using: /bin/sh ./script2: 16: Syntax error: word unexpected (expecting ")") *Using: /bin/csh bash: ./script2: /bin/csh: bad interpreter: No such file or directory bash: ./script2: /bin/env/csh: bad interpreter: No such file or directory PS: I'm on UBUNTU, and I'm a student with a professor that didn't talk about #!/usr/bin/env csh I tryed to study it on internet, but I don't understand what is, and How to configure it |
|
#6
|
||||
|
||||
|
Hi.
You can try: Code:
csh s1 However, in order to execute the file as a command like: Code:
./s1 Code:
whereis csh Code:
/bin/csh Code:
#!/bin/csh If whereis cannot find csh, then either you'll need to install it -- if csh is a requirement for the class -- or you'll need to learn to write the script in bash (or some other Bourne shell family shell). If all else fails, perhaps you need to chat with the prof. Please also see Rule #6 regarding school homework in the thread Simple rules of the UNIX.COM forums: ... cheers, drl --- Standard advice: avoid csh for scripting, use Bourne shell family. |
||||
| Google The UNIX and Linux Forums |