Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 $nameI 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

john
In shell script you have to write like this.
name=Mukesh
echo $nameThis 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 $3this will give u
Mukesh
K
Sharmaon 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
fiother 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
fiRegards
Mukesh K Sharma

Odd,
#!/bin/csh
set name = john
echo $nameworks 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.

...actually that was a bit ambiguous about ksh "if" syntax. I should maybe have said
if [[ condition ]]
then
do something...
fi

![]() |
Auto update script
|
RPC between unix and wind...
|

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