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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
environment variables radhika03 Shell Programming and Scripting 3 01-22-2007 01:58 PM
environment variables sumsin High Level Programming 6 03-13-2006 11:17 AM
help..Environment variables... sekar sundaram UNIX for Dummies Questions & Answers 3 08-30-2005 03:35 AM
environment variables Esaia High Level Programming 2 02-20-2003 08:19 PM
what is the use of Environment variables indianguru UNIX for Dummies Questions & Answers 2 07-24-2001 09:41 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2009
debbie15 debbie15 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 2
how to expand environment variables in a file?

I am new to unix and would appreciate if someone could help.

I have an environment variable SourceFilePath=/db1/Src/test set on the unix server.

I want to expand this SHELL variable in a file using any command sed, awk etc

File contents is as follows:

var=$SourceFilePath/file.txt

The command should create a new file by subsituting the environment variable with the actual value.

The output should look like this.

var=/db1/Src/test/file.txt
  #2 (permalink)  
Old 07-01-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,647
I think you mean to 'get the value of' a variable or maybe dereference it.

Do you mean you want to create a file using a variable as a filename?
Code:

SourceFilePath=/db1/Src/test 
var=${SourceFilePath}/file.txt
> $var     # this creates an empty file named /db1/Src/test/file.txt
  #3 (permalink)  
Old 07-01-2009
debbie15 debbie15 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 2
Hi Jim,
I want to substitute the value for ${SourceFilePath} and not create a file with the variable name. file.txt is already existing.

My scenario is like this.

file.txt is present on the TEST & DEV
I want to use the environment variable to point either to TEST or DEV.
So i will have one parameter file
PATH=$SourceFilePath/file.txt

I want to write a script which will generate a new file for the following system
TEST server should create a new file abc.txt with the following content

PATH=/db1/Src/test/file.txt

DEV server should create a new file xyx.txt with the following content

PATH=/db1/Src/dev/file.txt

The command or script must only substitute the value for the environment variable.

Thanks for your input.
Sponsored Links
Reply

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 12:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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