Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i set or change an environment variable using awk?

Status
Not open for further replies.

davomarcus

Technical User
Apr 7, 2005
1
US
Basically I want to take the output of the line below and execute it without writing the line into a file before hand or after...just on one command line.

For example, if I type one line at a time into the command line:

setenv dav 1
echo $dav produces the correct output in the shell a "1"

now:

in my directory I have another direcotry called:
something like XXXXXXXXXXXX999XXXX.

if I:

ls | awk '{print "setenv dav " substr($1,13,3)}'

returns into the shell:

setenv dav 999

the output of the awk works fine and delviers the desired value into the shell *but* it does not change the environment variable "dav" which was previously set to 1.

I also tried this variation and it does not work:

ls | awk '{print "setenv dav " substr($1,13,3)}' | tcsh

Why is this so difficult?

If I try something like this:

ls | awk '{system ( "setenv dav" $1 )}'

the "setenv" or "setenv dav" call is not recognized when it runs through the system call running though awk. If I change "setenv dav" to something like "cd /tmp" it will work, the system call works fine.

I am going nuts here and am to "fawk" it all when it comes to awk! (Don't mean to offend...just very frustrated here).

I would really appreciate some expert help.
I am running fedora core 3 in tcsh.
I am probably missing something very basic.

Thanks Much,
DavoMarcus
 
In ksh-like or bourne-like shell you may use the eval builtin.
Don't know for tcsh ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top