retaining the evironment varaibles...


 
Thread Tools Search this Thread
Operating Systems Linux retaining the evironment varaibles...
# 1  
Old 03-23-2007
retaining the evironment varaibles...

Hi all,

I wrote a shell script in which one of the if condition i tried to set few variables and exported them...and when i am out of if condition i wish to run one of my script which uses those variables exported.

But i found that when i am out of the if statement those variables were not set and were empty.

So please can any one help me where i am going wrong.....(below are the details)

pasting below the snippet of the script(setup)

#!/usr/bin/ksh
if [ "${1}" = "solaris" ]
then
(
LIBPATH=/usr/odbc/lib:/opt/$2/lib:/usr/odbc/drivers:$LIBPATH
export LIBPATH
ODBCINI=`pwd`/.odbc.ini
export ODBCINI
echo "ODBCINI="$ODBCINI "LIBPATH="$LIBPATH
)
fi
echo "ODBCINI="$ODBCINI

pasting console output

$sh setup solaris
ODBCINI=/export/home/testing/se185015/.odbc.ini LD_LIBRARY_PATH=/usr/odbc/lib:/opt/odbc32v52/lib:
ODBCINI=
# 2  
Old 03-23-2007
Try this ...Use curly braces {/} , not (/)

Quote:
#!/usr/bin/ksh
if [ "$1" = "solaris" ]
then
{
LIBPATH=/usr/odbc/lib:/opt/$2/lib:/usr/odbc/drivers:$LIBPATH
export LIBPATH
ODBCINI=`pwd`/.odbc.ini
export ODBCINI
echo "ODBCINI="$ODBCINI "LIBPATH="$LIBPATH
}
fi
echo "ODBCINI="$ODBCINI
# 3  
Old 03-23-2007
Oh thank you so much its working.......... Can you explain me why it worked with { } and not with ( )...

thanks in advance
# 4  
Old 03-23-2007
Quote:
Originally Posted by priya444
Oh thank you so much its working.......... Can you explain me why it worked with { } and not with ( )...

thanks in advance
( ) will always start a new shell...
# 5  
Old 03-23-2007
From the man page of ksh:
Code:
    (list)

         Execute list in a separate environment. If two  adjacent
         open parentheses are needed for nesting, a space must be
         inserted to avoid arithmetic evaluation.



    {list}

         list is simply executed. Unlike the metacharacters ( and
         ),  {  and  }  are  reserved words and must occur at the
         beginning of a line or after a ; in order to  be  recog-
         nized.

Since () creates a seperate environment, then the environment is different from your current env that has the variable.
# 6  
Old 03-23-2007
ok thanks i dint new about that.....well got to know now.... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Retaining value outside loop

Hi, I m new to shell scripting. I did some research and understand that unix treats while and other loops as new shell and hence the variable loose its value outside of the loop. I found solution for integer variable but in mycase this is a string variable. here variable loc is a... (6 Replies)
Discussion started by: knowyrtech
6 Replies

2. Shell Programming and Scripting

Retaining whitespaces...

There's an input file(input.txt) which has the following details : CBA BA <Please note the second record has a LEADING WHITESPACE which is VALID> I am using the following code to read the content of the said file line by line: while read p ; do echo "$p" done < input.txt This is the... (1 Reply)
Discussion started by: kumarjt
1 Replies

3. UNIX for Advanced & Expert Users

How to setup command and varaibles one time in a server?

Hi All, Am working on several solaris server and login as root. As soon as access the server as root user, i need to type in below command/set : bash;set -o vi Is there any root profile file i can set this, so that i don't need to keep typing this command as when i access the... (1 Reply)
Discussion started by: Optimus81
1 Replies

4. Shell Programming and Scripting

Retaining Pipeline values

Hi, I am trying to calculate a few values using the below code but it dosent seem to be working. for i in 1 2 3 4 5 6 7 8 do j=`expr $i + 3` x =`head -$j temp1|tail -1|cut -f24 -d","` y =`head -$j temp1|tail -1|cut -f25 -d","` c =`expr $x / $y` echo "$c" >> cal_1 done I am not... (4 Replies)
Discussion started by: sachinnayyar
4 Replies

5. Shell Programming and Scripting

help in retaining leading zero

Hello. I'm trying to add multiple numbers with varying length and with leading zeroes in it. However, I'm getting the sum (totalHashAccountNumber) without the leading zeroes in it. How do I retain the leading zeroes? Please pardon the lengthy code.. I'm getting the hash account number from 2... (2 Replies)
Discussion started by: udelalv
2 Replies

6. Shell Programming and Scripting

concatenate varaibles var1, var2 together to var1 again

HI i like to concatenate the two variables var1=$line (ie 22885068900000652 B86860003OLFXXX592123320081227) var2=$amount (ie 123456) i want to club together both the above varaible var1 & var2 and assign back to var1 right now i am doing like this but it is not working. var1=`echo... (1 Reply)
Discussion started by: kshuser
1 Replies

7. Shell Programming and Scripting

Retaining default OFS

Hi, I wat to remove the first two columns of the ls -l command: $ ls -l | awk '{ $1="";$2="";print;}' The only problem is now the columns of the output is space separated instead of the separators the ls -l originally throws. Can someone tell how to preserve the default OFS of an ls -l... (3 Replies)
Discussion started by: amicon007
3 Replies

8. Shell Programming and Scripting

retaining file path

hi all, Is there any way to retain file path? echo "Please enter your old filename" read a #user input : /blah/blah1 echo "please enter the new filename" read b #user input : dumb mv $a $b What i would like to do is for the user to enter just the "filename" for the new filename... (2 Replies)
Discussion started by: c00kie88
2 Replies

9. Shell Programming and Scripting

variable not retaining value

Bourne shell Solaris I'm trying to set a flag to perform an action only when data is found. So I initialize the flag with: X=0 Then I read the data: if ; then while read a b c do X=1 done < ${inputFile} fi The problem is that X will be set to 1 inside the while loop but when... (5 Replies)
Discussion started by: gillbates
5 Replies

10. Shell Programming and Scripting

Retaining value in var for flag.

I have problem like this : while loop 1 var=some expression 2 if then 3 Do something 4 oldVar=$var 5 fi 6 done Then, I am facing error at line number 2, mentioning invalid argument. Can anyone please help me for, How to retain value in oldVar? (4 Replies)
Discussion started by: videsh77
4 Replies
Login or Register to Ask a Question