The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
Accessing PL/SQL OUT variables in Korn Shell Script bright_future UNIX for Advanced & Expert Users 4 12-02-2008 12:02 PM
accessing shell script variable in file HIMANI UNIX for Dummies Questions & Answers 6 08-06-2007 11:07 PM
concurrency issue while Accessing Mail Box from shell script Sumit_Fundoo UNIX for Advanced & Expert Users 2 02-25-2007 02:23 PM
Accessing the home directory in shell script krishan SUN Solaris 1 05-21-2005 12:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2005
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
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 (permalink)  
Old 05-27-2005
jerardfjay jerardfjay is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 146
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 (permalink)  
Old 05-27-2005
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
yes, I have exported var

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

export var

It doesnt work.
  #4 (permalink)  
Old 05-27-2005
radhika radhika is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 51
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 (permalink)  
Old 05-27-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
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 (permalink)  
Old 05-28-2005
videsh77 videsh77 is offline
Registered User
  
 

Join Date: Aug 2004
Posts: 144
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 (permalink)  
Old 05-28-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0