Sponsored Content
Top Forums UNIX for Dummies Questions & Answers how to expand environment variables in a file? Post 302330557 by debbie15 on Wednesday 1st of July 2009 04:08:09 PM
Old 07-01-2009
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Environment Variables in text file and read command

I cannot get the following substitution ($ORACLE_SID) to work: The variable ORACLE_SID is set to wardin my environment. It has been exported. I have a text file called test.dat: /u07/oradata/${ORACLE_SID}/extab/finmart/summit/ps_voucher_line_crnt_ex.dbf... (2 Replies)
Discussion started by: bradyd
2 Replies

2. Shell Programming and Scripting

For loop using input file doesn't expand variables

Hi, I'm using a for loop reading from an input file that contains files, whose path includes a variable name. But the for loop doesn't expand the variable and therefore can't find the file. Here's an example: File BACKUPFILES /home/John/alpha /home/Sue/beta... (8 Replies)
Discussion started by: Hesiod
8 Replies

3. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

4. Shell Programming and Scripting

dynamic variables - eval - expand etc.

Hello, so i'm making a script, using dynamic variables and trying to expand them. So far it hasn't worked out too well so it seems that I need some help from you, the elite. Example: #!/bin/sh counter=0 until (($counter>5)) counter2=1 until (($counter2>6)); do if ;... (5 Replies)
Discussion started by: TehOne
5 Replies

5. Shell Programming and Scripting

Setting environment variables in Cron file

Hi, In Cron file i'm using username and password hard-coded and now i wann to use environmental veraiables in cron file. But Could you please guide me how to use these environmental variables in cron file ? Thanks, Shyamu.A (4 Replies)
Discussion started by: shyamu544
4 Replies

6. Shell Programming and Scripting

environment variables in a sed script file

Hello Everyone I need to create a script file which must append some lines to a target text file, I'm using sed for windows, the script file look like this: { a\ STRINGTABLE DISCARDABLE\ BEGIN\ 5, 150 {a\ #define RC_SHELL, "%ID_SHELL%"\ #define RC_NAME, "%ID_NAME%"\ END } ... (1 Reply)
Discussion started by: edgarvm
1 Replies

7. Shell Programming and Scripting

Setting environment variables from a file :

Hi, I have around 10 environment variables in my shell script. i want to set this all in a file and just call that file in my shell script. How can i do that ? Please help. TIA! (6 Replies)
Discussion started by: qwertyu
6 Replies

8. HP-UX

Environment Variables

Hi All, I need to understand following three environment variables and their usages in HP Unix. _M_ARENA_OPTS _M_CACHE_OPTS PTHREAD_SCOPE_SYSTEM How does these environment variables influence multi threaded applciation and how do we decide the value of these variables? Is there... (0 Replies)
Discussion started by: angshuman
0 Replies

9. UNIX for Beginners Questions & Answers

Expand Variables and Wildcards into another variable.

Dear Forum members, I am having trouble getting the complete filename (and directory path) in a variable. Output directory mentioned in the code have three files: DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_london.out DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_paris.out... (4 Replies)
Discussion started by: chetanojha
4 Replies

10. Shell Programming and Scripting

Challenge with sh script using environment variables to check for file.

Hi All Thanks for reviewing my question. I have a sh script where I used an environmental variable for the directory for the file I need to check to ensure before executing a process. I have confirmed the permissions and I can find the file if I use a hard coding of the directory. This is a... (5 Replies)
Discussion started by: rstojkovic68
5 Replies
set(1F) 							   FMLI Commands							   set(1F)

NAME
set, unset - set and unset local or global environment variables SYNOPSIS
set [ -l variable [ =value]] ... set [ -e variable [ =value]] ... set [ -ffile variable [ =value]...] ... unset -l variable... unset -f file variable... DESCRIPTION
The set command sets variable in the environment, or adds variable=value to file. If variable is not equated it to a value, set expects the value to be on stdin. The unset command removes variable. Note that the FMLI predefined, read-only variables (such as ARG1), may not be set or unset. Note that at least one of the above options must be used for each variable being set or unset. If you set a variable with the -ffilename option, you must thereafter include filename in references to that variable. For example, ${(file)VARIABLE}. FMLI inherits the UNIX environment when invoked. OPTIONS
-l Sets or unsets the specified variable in the local environment. Variables set with -l will not be inherited by processes invoked from FMLI. -e Sets the specified variable in the UNIX environment. Variables set with -e will be inherited by any processes started from FMLI. Note that these variables cannot be unset. -ffile Sets or unsets the specified variable in the global environment. The argument file is the name, or pathname, of a file containing lines of the form variable=value. file will be created if it does not already exist. Note that no space intervenes between -f and file. EXAMPLES
Example 1: A sample output of set command. Storing a selection made in a menu: name=Selection 2 action=`set -l SELECTION=2`close NOTES
Variables set to be available to the UNIX environment (those set using the -e option) can only be set for the current fmli process and the processes it calls. When using the -f option, unless file is unique to the process, other users of FMLI on the same machine will be able to expand these vari- ables, depending on the read/write permissions on file. A variable set in one frame may be referenced or unset in any other frame. This includes local variables. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
env(1), sh(1), attributes(5) SunOS 5.10 5 Jul 1990 set(1F)
All times are GMT -4. The time now is 03:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy