0

Somehow to interact with user using shell in Linux you can use dialog.
my question about dialog --inputbox where you let user to enter a string as an answer to a question then you can redirect the result to /tmp/input.$$ and you can save it as following:
dialog --inputbox "Enter you first name:"10 40 2>/tmp/input.$$

x=`cat /tmp/input.$$`

Till now that's great !,but what if I write a script so I have to assign "dialog ...." to xterm which will open when user click on script file.
The main problem if I did assigning I'll find nothing in /tmp/input.$$
The code now :

xterm -e dialog --inputbox "Enter your first name" 10 40 2>/tmp/input.$$
x=`cat /tmp/input.$$`

then how can I save the value user entered in a variable to use it later ?
Any idea ? even if with different method !
Thanks in Advance

1 Answer 1

1

You need to use quoting to get the redirection to happen in the right place; as written, the output of the xterm itself (which is probably empty) is being redirected. You also need to specify a shell, since xterm -e will otherwise exec the command directly; redirection requires the shell.

xterm -e sh -c 'dialog --inputbox "Enter your first name" 10 40 2>/tmp/input.'$$
x=`cat /tmp/input.$$`

You may want to consider using something like zenity or kdialog instead of dialog, in order to avoid the extra xterm.

(And in bash the second line is better written as x=$(< /tmp/input.$$).)

5
  • Great Mr.geekosaur !...but it shows me an error here it is:"cat: /tmp/input.7562: No such file or directory " why ?
    – wisdom
    Apr 20, 2012 at 22:10
  • It's it...Solved ! sorry, but I thought you've made a mistake to write a single quote before $$ not after !,sorry again
    – wisdom
    Apr 20, 2012 at 22:24
  • sigh What you're trying to do is difficult (really, I'm serious about using zenity instead) because of needing to force stuff through the extra xterm; any problems with the command etc. are going to be lost when the xterm goes away. (Maybe try adding -hold.) Look in /tmp to see if you have some other /tmp/input.* files sitting around, is all I can think of.
    – geekosaur
    Apr 20, 2012 at 22:25
  • Ah, ok. I wondered if I should comment on that; it is somewhat tricky.
    – geekosaur
    Apr 20, 2012 at 22:25
  • I'll try to use zenity as soon as I read about it :),thnx
    – wisdom
    Apr 20, 2012 at 22:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .