Bash Dialog
Hello All,
Can someone please example the following to me: Code:
#!/bin/bash Code:
coices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) Josh |
Well, this is a rather weird example.
First of all, there is absolutely no need, to include the definition of cmd and options twice in this script. Likewise, echoing the $options variable twice is presumably also unwanted behaviour. It should rather be Code:
echo $choices Code:
cmd=(dialog --clear --title "Exchange" --menu "Please select exchange" 20 51 4) In other words, Code:
cmd[0] = dialog Now, the commands Code:
${cmd[@]} The redirection 2>&1 takes place in the original example since dialog returns its choices in stderr, which has number 2. Here is a modified version: Code:
#!/bin/bash Code:
choices=$( ... ) 1. The 3>&1 makes descriptor 3 hold the value of descriptor 1, which is stdout 2. The 1>&2 makes descriptor 1 hold the value of descriptor 2, which is stderr 3. The 2>&3 makes descriptor 2 hold the value of descriptor 3, which holds stdout after our first step. 4. Finally, we delete the descriptor 3... it was just a temporary descriptor to swap stdout and stderr EDIT: There remains one question: Why is such heavy redirection necessary? Well, stdout of dialog is redirected to stderr, which is displayed and not recorded into the variable $choices. Therefore, the user can actually interact with the script. If one would only redirect stderr to stdout, the user would not see that much. Try it! So, there is still one problem left, with the above solution. It currently does not work with menu titles like "Choose your destiny:". I hope that some string escaping guru will have a look and resolve the issue. Finally, credit goes to: http://tldp.org/LDP/abs/html/arrays.html for the arrays and http://www.problem-hilfe.de/linux/h/...Umlenkung.html (german) http://www.cc-c.de/german/linux/linux-dialog.php (german, too) for the dialog and redirection stuff. Here is some more english documentation: http://tldp.org/LDP/abs/html/commandsub.html for the $(...). and http://tldp.org/LDP/abs/html/io-redirection.html for the redirections. Hope, this helps a bit. |
It appears that this is poorly typed to me.
First there is no need to repeat the two cmd= lines with options as they are the same. Second I suspect coices was meant to say "choices". Third I suspect the first "echo $options" was meant to be "echo $choices". The intent of the line you asked about then becomes obvious - it is to show what choice the user made from the menu. |
See the dialog option '--stdout'.
|
Incorporating gnashley's suggestion, my code would look like:
Code:
#!/bin/bash |
This does what you want:
Code:
choices=$(dialog --clear --stdout --title Title --menu Menu 20 52 4 CMD "hello" CBOE "hello") ; echo $choices |
Thank you all, this is the first time I have used dialog, so just trying to understand it.
Josh |
All times are GMT -5. The time now is 08:55 PM. |