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

Re: .ini files in bash?



* Cameron Hutchison <camh+dl@xdna.net> [2004 Nov 29 15:15 -0600]:
> Ok. I got bored and spend a minute writing this:
> 
> function savevars()
> {
>     for var in "$@" ; do
>         eval "echo $var=\\\"\$$var\\\""
>     done
> }
> 
> 
> Just call it like:
> savevars VAR1 VAR2 VAR3 >file
> 
> then load the vars with:
> source ./file

Very nice little code snippet.  Thanks for posting this.  I'm trying to
learn more about shell scripting and I'm a bit puzzled why there are
two escaped backslashes.  After removing the obvious ones for quoting I
get:

$var=\"$$var\"

So the embedded quotes have to be escaped again?  I'm still learning
about the magic of eval, so a little more explanation would be
appreciated.

- Nate >>

-- 
 Wireless | Amateur Radio Station N0NB          |  Successfully Microsoft
  Amateur radio exams; ham radio; Linux info @  | free since January 1998.
             http://www.qsl.net/n0nb/           |  "Debian, the choice of
             My Kawasaki KZ-650 SR @            |     a GNU generation!"
        http://www.networksplus.net/n0nb/       |   http://www.debian.org



Reply to: