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

[debian-knoppix] Advanced Shell-Programming + Dialog



Hi,

just want to share an experience I just made ;-), which can be very useful for 
all programmers that use (X)dialog ...

You all know the redirection, so we do:

dialog --inputbox "Your name?" 0 0 2>$SOMETMPFILE
NAME=$(cat $SOMETMPFILE)

Klaus always said, that there must be some shell magic possible ;-) to avoid 
that temp-file, which can btw also be quite insecure and he was right:

The following works:

exec 3>&1 # make 3 point to stdout
NAME=$(dialog --inputbox "Your name?" 0 0 2>&1 1>&3) # basically redicrect 
stdout to #fd3, then redirect stderr to stdout
	
The trick is that the $()-construct just redirects #1 stdout descriptor, but 
not the #3, even if it also points to stdout ... :-)

And what the best is, that can be even more simplified. Make for example the 
following procedure:

dia()
{
	dialog "$@" 2>&1 1>&3
}

And you can just use dia, after you have setup the #3 fd, just as a normal 
command:

NAME=$(dia --inputbox "Your name?" 0 0)

All the magic necessary for redirection is done by the procedure.

I found that out, while I needed a way to somehow close the FDs for another 
application (upcoming nxserver). You can read everything about it in the 
Advanced Bash Scripting Guide:

http://www.tldp.org/LDP/abs/html/io-redirection.html

cu

Fabian

_______________________________________________
debian-knoppix mailing list
debian-knoppix@linuxtag.org
http://mailman.linuxtag.org/mailman/listinfo/debian-knoppix



Reply to: