Computing.Net > Forums > Unix > Simple shell script(csh) needed

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.

Simple shell script(csh) needed

Reply to Message Icon

Name: bce_groups
Date: March 17, 2009 at 07:40:01 Pacific
OS: Windows XP
Subcategory: General
Comment:

HI ,

In the below script I am trying to return the value of the environment variable TIBCO_HOME to the caller

#! /usr/bin/csh

set VAR_NAME=$1

echo VAR_NAME

On the aix console.. set to setenv TIBCO_HOME /app/tibco

When I execute the script… myscript.sh TIBCO_HOME, the script prints TIBCO_HOME. But I am expecting /app/tibco.

Can anyone help me to fix this?


Thanks,

Babu



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 17, 2009 at 07:47:53 Pacific
Reply:

You forgot the dollar sign for echoing the contents of a shell variable:

echo $VAR_NAME


0

Response Number 2
Name: bce_groups
Date: March 17, 2009 at 18:41:01 Pacific
Reply:

HI,
Thanks for your response.
I changed my script but still the script prints TIBCO_HOME.

I am invoking the script as "csh -f test1.sh TIBCO_HOME"

echo $TIBCO_HOME on unix console returns /app/tibco, I want the same output from my script.

Below is the modified script..

#! /usr/bin/csh
set VAR_NAME=$1
echo $VAR_NAME

Thanks,
bce


0

Response Number 3
Name: nails
Date: March 17, 2009 at 21:30:36 Pacific
Reply:

First, there is no reason for you to do this:

csh -f test1.sh TIBCO_HOME

Since you are invoking csh in your script with #!/usr/bin/csh there is no reason to spawn the extra shell. This will do the job just as well:

test1.sh TIBCO_HOME

Second, if you are trying to pass argument 1, and then echo that as an environmental variable, then this should work. If TIBCO_HOME isn't defined, the script will error out:

#! /usr/bin/csh

# this script, test1.sh, takes one argument, TIBCO_HOME in this case:
# test1.sh TIBCO_NAME
# then, echo out the shell environmental variable TIBCO_HOME

eval echo \"\$${1}\"


0

Response Number 4
Name: psiva_unix
Date: March 24, 2009 at 01:02:43 Pacific
Reply:

Babu,

See the below script, i hope it will clear your doubts

#!/usr/bin/csh
#Get the env variable values

set JP=$1
echo $JP # user given input values
echo $JAVA_BINDIR # Env variable

Run:
$ ./env_val.csh Testinput

Output:

Testinput
/usr/lib/java/jre/bin

Note:
if you want change the env file variable and values after that you have to source the env files. then only it will affect the env file.

for sourcing the env file:

$ . . env

Thanks


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Simple shell script(csh) needed

Need simple Shell Script www.computing.net/answers/unix/need-simple-shell-script/6145.html

Shell Script Help Needed www.computing.net/answers/unix/shell-script-help-needed/2821.html

shell script www.computing.net/answers/unix/shell-script-/4295.html