to export environment variables in a file
hi,
I want to export the env variables in a file using a script,i tried using the below: for var in 'env' do var2=env|awk -F '=' '{print$1}' echo "$var;export $var2">file.txt done but i m nt getting the desird o/p,i need every variable to be appended with ;export "variable name" in the target file wil sm1 hlp pls |
Hi,
What you have written is very confusing.Please elaborate with proper example. Refer this link for exporting environmental variables http://tldp.org/LDP/abs/html/othertypesv.html |
Hi
Prayag is right - explain in what context you are trying to export your environment variables - what is it that you're trying to achieve in the bigger picture? Also: Quote:
|
Quote:
I wish to take the o/p of env command(which will give the list of environment variables) in a file say env_file.txt.for example, say env_file has the below content: ORACLE_HOME=/data/oracle/app/product/ora10g PWD=/home/amit . . . Now , i wish to create another file myappfile through a script which will have the contents like below: ORACLE_HOME=/data/oracle/app/product/ora10g;export ORACLE_HOME PWD=/home/amit;export PWD 'myappfile' is required for my application. |
Hi,
Follow this example on your command line you will get the answer yourself: Code:
echo $MYNAME Code:
export MYNAME=vinayak Code:
echo $MYNAME |
Hi
From the terminal try: Code:
# env >> myappfile.txt |
I have one application which requires the 'myappfile' as it is below:
ORACLE_HOME=/data/oracle/app/product/ora10g;export ORACLE_HOME PWD=/home/amit;export PWD Currently what we do is we manually create the myappfile by adding ";export variablename " for each environment variable. I need a script which will append the ";export variablename " at the end of each variable and the endresult would be : ORACLE_HOME=/data/oracle/app/product/ora10g;export ORACLE_HOME PWD=/home/amit;export PWD |
Read this post around how to append to a file with the sed command.
Thus your process to do this would be to write the env variables to your output file and then use sed to append "; export XXXXX" Note you need to read up and understand sed before you can achieve this. |
Code:
awk -F= '{ print $0 "; export", $1 }' input_file > output_file |
Thanx colucix,It worked..for dynamic variables we regenerate the required file.
|
All times are GMT -5. The time now is 06:26 AM. |