[prog] Shell question...

John Clarke johnc+linuxchix at kirriwa.net
Fri Dec 10 18:16:21 EST 2004


On Fri, Dec 10, 2004 at 02:32:58 +0100, Riccarda Cassini wrote:

> Problem is, I'd rather have those variables available in the main shell
> (the parent process), because many of them are subsequently being used
> in a multitude of places all over the script.

You could put the while lot into an eval, which is ugly but it works,
and doesn't leave child processes hanging around until the script
finishes:

    eval `echo bla blah blurb | while read FOO BAR BAZ; do echo FOO=$FOO; echo BAR=$BAR; echo BAZ=$BAZ; done `

To make it more readable, put the while loop into another shell script
like this:

    #!/bin/sh
    # read_vars.sh
    while test $# -ne 0
    do  
        read -d ' ' VALUE
        echo "$1=\"$VALUE\""
        shift
    done

Run it like this:

    #!/bin/sh

    eval `echo bla blah blurb | ./read_vars.sh FOO BAR BAZ`
    echo $FOO
    echo $BAR
    echo $BAZ

I don't know if this can be done more efficiently, but at least you now
have something that's readable and doesn't leave all those child
processes hanging around :-)

> Actually, I kept being curious, and finally did find
> 
>     ^V             Display version of the shell.
> 
> being mentioned in the man page section "Emacs Editing Mode".

That's also in the PD version, but I found $KSH_VERSION first :-) 


Cheers,

John
-- 
> ... I can use the cheaper frozen goat for IDE?
Though you _can_ sacrifice things to an IDE bus, there are no reports of
them ever sucking any less as a result, so it's likely a waste of a goat.
            -- Anthony de Boer


More information about the Programming mailing list