parsed.org

Tips by tag: environment

Environment Variable Editing by cygnus on Jan 19, 2005 10:39 PM

You can edit an environment variable in-place by running vared:

$ vared PATH

It will give you a readline-style buffer to edit the variable's contents and will save them back to the environment after you're done.

environmentpathreadlinevaredzsh
Variable Indirection by xinu on Jan 31, 2006 10:06 AM

Sometimes you need to iterate over variable names and access their values. In shell script, you would do something like this to get the values of FOO and BAR:

$ FOO=apple
$ BAR=orange
$ VARS="FOO BAR"
$ for v in $VARS ; do echo ${!v} ; done

The above works in bash. Use this in Zsh:

$ for v in $VARS ; do echo ${(P)v} ; done

(The 'P' flag on ${v} causes a further variable lookup before ${v} is evaluated.)

Thanks to Cliff for the tip!

bashcommandsenvironmentevaluationiterationloopshellzsh
RSS