[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: .ini files in bash?



In article <[🔎] 200411290924.30130.d_baron@012.net.il>,
David Baron  <d_baron@012.net.il> wrote:
>How might one save and restore setting of variables in a bash script to and 
>from a file in one's home (or sub-) directory?

Okay so everybody's trying to outdo eachother trying to write
sed scripts that do proper quoting. I'd like to recommend reading
the bash or any other POSIX shell manual instead.

To save variables:

	export -p > envfile

To read them back:

	. envfile

See, for example, "man ash":

     export -p
            With no arguments the export command lists the names of all
            exported variables.  With the -p option specified the output will
            be formatted suitably for non-interactive use.

One minor nit though: the output of 'export -p' is not guaranteed to
be readable for every POSIX shell. Bash and zsh generate "declare -x"
statements that can't be read by a standard POSIX shell like ash.
Perhaps a bug report is in order ... in the mean time, make sure
you only import variables into the same shell you exported them
from or use this tiny code fragment I'm posting here trying to
outdo all the other sed l33t h@xors:

export | sed -e 's/^\(export\|declare -x\|typeset -x\|\)/export /' > envfile

That would be reasonably portable.

Mike.



Reply to: