Env vars in a SED script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Env vars in a SED script
# 1  
Old 05-09-2006
Env vars in a SED script

Hello,
<Preamble>
I'm writing an installation script for use with PKGADD. What I want to do is take one of the variables set in the REQUEST script and use that in the install script so I can change applications configuration.

My install script is as follows:
Code:
sed '
/^DIRNAME/ i\
JAVA_HOME=$JAVA_HOME
' <../../tmp/run.sh >run2.sh

JAVA_HOME is an environment variable set in the request script..
But the output is:
Code:
JAVA_HOME=$JAVA_HOME
DIRNAME=`dirname $0`

</Preamble>

How do I correctly refference an evironment variable in a SED script?
# 2  
Old 05-09-2006
sed using variables

Bags,

Try using double quotes " instead of single quotes ' in your sed statement.

This allows you to still pass variables as you require.
# 3  
Old 05-09-2006
use double-quotes.
# 4  
Old 05-11-2006
When I change the command to:
Code:
sed "
/^DIRNAME/ i\
JAVA_HOME=$BASEDIR
" <../../tmp/run.sh >run2.sh

I get and error:
Code:
sed: command garbled: /^DIRNAME/ iJAVA_HOME=

"Use double quotes" is a fairly easy command to follow.
Yet I must ask, "what am I doing wrong?"
# 5  
Old 05-11-2006
Quote:
Originally Posted by Bags
When I change the command to:
Code:
sed "
/^DIRNAME/ i\
JAVA_HOME=$BASEDIR
" <../../tmp/run.sh >run2.sh

I get and error:
Code:
sed: command garbled: /^DIRNAME/ iJAVA_HOME=

"Use double quotes" is a fairly easy command to follow.
Yet I must ask, "what am I doing wrong?"
how 'bout:
Code:
sed "
#^DIRNAME# i\
JAVA_HOME=$BASEDIR
" <../../tmp/run.sh >run2.sh


Last edited by vgersh99; 05-11-2006 at 12:11 PM..
# 6  
Old 05-11-2006
It executes.. but the pattern is not matched anywhere in run.sh..
So a diff between the input and output shows no change.

As a side note, my last error correctly interpreted $BASEDIR.
# 7  
Old 05-12-2006
I'm still going crazy trying to get this thing to work..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Env variables in script

Hi All, I have script and it's hardcoded the script ca invoke in user home dir and logs will be redirected to home dir of user. how to make the same script will be invoke from /usr/bin with out chg the logs and other functions path from /user/homedir . code is below: pls check how to... (1 Reply)
Discussion started by: saku
1 Replies

2. Shell Programming and Scripting

List of Shell Env Vars

Hia, echo ${!S*} gives me all those env vars starting with S like SHELL SECONDS SHELLOPTS SHLVL etc. is there any way to deflate the shell variables' range like echo ${!A-E*} OR echo ${!A..S*} to list all env vars starting within range of A till E. Thanks Regards, Nasir (1 Reply)
Discussion started by: busyboy
1 Replies

3. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

4. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

5. Shell Programming and Scripting

forcing modified env vars to be effective

Hi I have a /bin/sh script, that when executed changes some env vars (like $path). How can I source the modified cshrc? I dont want to logout and login to have the modifed path. sh doesnot recognize source as I understand it is defined only in bash rehash also doesnot work.. Any ideas... (10 Replies)
Discussion started by: jake_ryan
10 Replies

6. Shell Programming and Scripting

Script ENV issue?

Whenever I execute the following korn shell script command I get this error. su - feeduser export: =0: not identifier ** Here is the part of the script with the error ** # Set db type (PRODUCTION, DEVELOPMENT, QA, UA) # unset DB_TYPE_ERROR $HOME/share/$DBS_NAME $ORACLE_SID... (3 Replies)
Discussion started by: soupbone38
3 Replies

7. Shell Programming and Scripting

get env variable from last script

I have 2 scripts t2.sh calls t1.sh. I need to get the vaule of a env variable from t1.sh /tmp/test$ cat t1.sh #!/bin/sh INSTANCE="font/fc-cache" export INSTANCE svcadm disable ${INSTANCE} /tmp/test$ cat t2.sh #!/bin/sh . /tmp/test/t1.sh echo ${INSTANCE} The above works... (9 Replies)
Discussion started by: honglus
9 Replies

8. Shell Programming and Scripting

How to execute script one by one in automated env

I have scripts and when I run mannualy it passed but I would like to run one by one at a time like automated. But When I run in one by one in automated the 1st one is executed and did not jump to 2nd one.Please suggest how to run one by one at a time in automated env. sample of Script ... (1 Reply)
Discussion started by: madhusmita
1 Replies

9. Shell Programming and Scripting

Env Variable substituion in Sed (-s option)

Folks, I've been trying to use the ENV variable with slashes(/) in its value inside the sed substitution.. Sed 's/myval/'$MYVAL'/' file1 >> file.tmp If MYVAL=<sometext>, it works. if MYVAL=/home/venkat, it doesnt. *************************** bash-2.05$ export VAL=/home/venkat... (5 Replies)
Discussion started by: gvsreddy_539
5 Replies

10. Shell Programming and Scripting

Adding command line env in cron env

Hello friends, i run two scripts manually & they work. i run them in cron & they don work. how to match the two env's 1.command line env 2.cron env i would like cron to use command line env. Thanks & Regards Abhijeet (1 Reply)
Discussion started by: abhijeetkul
1 Replies
Login or Register to Ask a Question