Computing.Net > Forums > Unix > unix shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix shell script

Reply to Message Icon

Name: john
Date: July 22, 2003 at 22:09:05 Pacific
OS: slackware
CPU/Ram: 256
Comment:

I have a beginner's question about unix shell(csh). When I run following commmand from csh shell:
%>set name = john
%>echo $name
%>john
It works just fine, but I run them as a unix script:
#!/bin/csh
set name = john
echo $name

I don't get any output and I have no clue why this is happening. In addtion to that, when I do some research on, say ,"if else statement", some web-site says like
if (some stuff); then
,but other site says like
if [some stuff] then
I have no idea where the heck those inconsistant difference come from.
Please give me some advice



Sponsored Link
Ads by Google

Response Number 1
Name: msharma
Date: July 23, 2003 at 02:16:38 Pacific
Reply:

john

In shell script you have to write like this.

name=Mukesh
echo $name

This will definetly give you Mukesh on prompt.

If you want to use set in shell script then you have to use like this.

set Mukesh K Sharma
echo $1
echo $2
echo $3

this will give u

Mukesh
K
Sharma

on prompt. Note that $0 is the name of shellscript u are using.

Regarding if .... As far as i know in shell script you have to use if like this only .

if [ u -eq 1 ]
then
echo u equals to 1
else
echo u not equals to 1
fi

other usage of if condition is using test also

if test u -eq 1
then
echo u equals to 1
else
echo u not equals to 1
fi

Regards
Mukesh K Sharma



0

Response Number 2
Name: WilliamRobertson
Date: July 23, 2003 at 10:52:10 Pacific
Reply:

Odd,

#!/bin/csh
set name = john
echo $name

works for me.

However C shell is considered evil by many shell scripters. It has quite different syntax to sh, ksh, bash and zsh (which are all broadly compatible with each other), for example the construction you mentioned:

if (condition) do something

This may have the advantage of being similar to C, Perl, Awk, Java and JavaScript, but csh is so lacking as a scripting language I can't personally be bothered with it.

In ksh that would be

if [[ condition ]] # Note double brackets

or for numeric conditions,

if (( condition ))

ksh also supports the old [ ] syntax (single brackets), which makes it flexible, but this can be confusing when you see both used.



0

Response Number 3
Name: WilliamRobertson
Date: July 23, 2003 at 10:54:49 Pacific
Reply:

...actually that was a bit ambiguous about ksh "if" syntax. I should maybe have said

if [[ condition ]]
then
do something...
fi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Auto update script RPC between unix and wind...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: unix shell script

Unix Shell Script www.computing.net/answers/unix/unix-shell-script/3580.html

Unix shell script runing SQL files www.computing.net/answers/unix/unix-shell-script-runing-sql-files/5286.html

Unix shell script problem... www.computing.net/answers/unix/unix-shell-script-problem/6217.html