Accessing var from .profile into shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Accessing var from .profile into shell script
# 1  
Old 05-27-2005
Accessing var from .profile into shell script

I have defined variable in .profile file. This variable, I tried to use in a shell script
for the same session. In Shell script it is not finding this variable, but the same variable
on the console if I try to access by echo $var, it is giving me correct assigned value.

Can anyone, please guide me how to use variable defined in .profile in the shell script?
# 2  
Old 05-27-2005
Quote:
Originally Posted by videsh77
I have defined variable in .profile file. This variable, I tried to use in a shell script
for the same session. In Shell script it is not finding this variable, but the same variable
on the console if I try to access by echo $var, it is giving me correct assigned value.

Can anyone, please guide me how to use variable defined in .profile in the shell script?

Did you export the variable to the environment before using it in the session?
# 3  
Old 05-27-2005
yes, I have exported var

Yes, I have exported this variable to environment by using,

export var

It doesnt work.
# 4  
Old 05-27-2005
This is how you normally define it and use it:
In your profile you should have-
export SCRIPTSD_P=$HOME/2005/some_dir
#This is how you use it in your script-
$SCRIPTSD_P/perf_jobs.sh

This is not a solution but let me tell you some thing. Hopefully, you are not doing that in your shell script. One time I tried to change the value of $SCRIPTSD_P in a shell script and I re-executed my .profile from within the shell script. Ex:

#Some shell script
export $SCRIPTSD_P=$HOME/2005/some_new_dir
#re-executing the profile into the current session.
. $HOME/2005/.profile

But, for some reason $SCRIPTSD_P didn't take the new value. I never could find out why. Did you check to see if you are changing the variable's value.
# 5  
Old 05-27-2005
Quote:
I have defined variable in .profile file. This variable, I tried to use in a shell script
for the same session. In Shell script it is not finding this variable, but the same variable
on the console if I try to access by echo $var, it is giving me correct assigned value.

Can anyone, please guide me how to use variable defined in .profile in the shell script?

What is your shell ?
How are you using the variable in the script ?
and
how you are running the script. ?
# 6  
Old 05-28-2005
I have a Korn Shell.

In my script, if I need to read some file, then common path to file is in this variable.

fName=$Access_Dir/FileName.txt
awk '{print $0}' fName
Second line awk is symbolic, I have one awk operation with fName.

I am running this script from command prompt.
# 7  
Old 05-28-2005
Quote:
Originally Posted by videsh77
I have a Korn Shell.

In my script, if I need to read some file, then common path to file is in this variable.

fName=$Access_Dir/FileName.txt
awk '{print $0}' fName
Second line awk is symbolic, I have one awk operation with fName.
... although it's "symbolic", but...... shouldn't it be like so:
awk '{print $0}' $fName

Quote:
Originally Posted by videsh77
I am running this script from command prompt.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Accessing secured server using shell script

Hi, I was trying to connect secure server using SFTP, but end up in error. Im looking for a shell script which will connect my secured FTP server For EG: hostname = example.com username = fed password = pass port = 993 Destination = web Push some tar file into web folder which is in... (3 Replies)
Discussion started by: Paulwintech
3 Replies

2. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

Hi All, I have a shell script called sample1.sh where I have 2 variables. Now I have another shell script called sample2.sh. I want the variables in sample1.sh to be available to sample2.sh. For example. In sample1.sh I am finding the sum of 2 numbers namely a and b. Now I want to access... (2 Replies)
Discussion started by: rsendhilmani
2 Replies

3. UNIX for Advanced & Expert Users

Accessing PL/SQL OUT variables in Korn Shell Script

Hello All, I was just wondering if there is any direct way to access PL/SQL OUT variables from Korn Shell Script. I could already figure out how to return a single value back from PL/SQL to Shell Script (using bind variable). But, what if we want to return multiple values? One option I... (4 Replies)
Discussion started by: bright_future
4 Replies

4. Shell Programming and Scripting

Accessing php script from shell script

Hi I'm a newb to php scripts. My task requires me to run a shell script from within the php script which I believe I've figured out. What I'm trying to do now is output something to the web page from the called shell script. when I use "echo" from the called shell script I don't get any output... (3 Replies)
Discussion started by: airon23bball
3 Replies

5. Shell Programming and Scripting

Accessing aliases within a shell script

I am not able to access the aliases in my environment within a Python script. If I pass the alias to os.system(), I get a message saying "sh: x: not found". I've tried sourcing my .bashrc file in the script, but this does not work. I would perfer not to source my or any rc file because this... (9 Replies)
Discussion started by: cooldude
9 Replies

6. Shell Programming and Scripting

Accessing variables of one shell script in another shell script

I have a variable $exe in a shell script file a.sh which I need to access in another shell script file b.sh. How can I do that? :rolleyes: Thanks!! (2 Replies)
Discussion started by: looza
2 Replies

7. Shell Programming and Scripting

Accessing the parameters of a shell script

Hi, I have one situation. I am developing a shell script to which parameters will be passed from a Web based User Interface using some Business Process(BP).There are some 6 parameters for which user will enter the values in UI. These values will be passed to script by BP in the form -... (2 Replies)
Discussion started by: The Observer
2 Replies

8. UNIX for Dummies Questions & Answers

accessing shell script variable in file

Hi, I have a shell script in which there is a file conn_$temp where $temp has the pid of the shell script. in this shell script i have an embedded awk script that must read the file while ((getline < "conn_$temp") > 0) However due to the "$temp" in the file name, the awk script is... (6 Replies)
Discussion started by: HIMANI
6 Replies

9. UNIX for Advanced & Expert Users

concurrency issue while Accessing Mail Box from shell script

Hi Bros, I am in a serious trouble with concurrency issue while using mailx. I have a shell script which reads all the emails of a unix user account and create a copy (another mbox for processing and archive purpose). This script works fine for 99.99% of the time but sometime it start creating... (2 Replies)
Discussion started by: Sumit_Fundoo
2 Replies

10. Solaris

Accessing the home directory in shell script

How can I access home directory in a shell script. I am writing a script which will delete the log files in each of the user's directory Krishan (1 Reply)
Discussion started by: krishan
1 Replies
Login or Register to Ask a Question