I have to get "export" lines from a remote file on another server, then set the current sh session env dynamically.

However, echo with export doesn't seem to work.

echo `export CONFIGA=configurationA`

I try to create this script as generic and as simple as possible, cause there are many export statements from the remote file, and not all is used. The ones I need will be determined by certain patterns, but the number of those statements is also dynamic.

Now I wonder if this can be done in ksh script, but I have no other options at the moment.


There's probably a more elegant way to do this, but you could pull your desired variables from that remote file into a local temporary file:

file=/tmp/tempfile.$RANDOM ## AIX doesn't come with mktemp
> $file || echo Failed to pick a good tempfile name
grep "export CONFIG.=" some-file > $file

Then use the . builtin to read that file:

. $file

and of course, clean up:

rm $file
  • Beautiful! Thanks Jeff, and thanks for fixing the title. – wez Jun 7 '16 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.