| Author |
Message |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Mon 17 Oct 2011, 22:43 Post subject:
Xdialog input tags and items (SOLVED) |
|
Xdialog has a number of widgets that take variable input in the form of "tag1 item1 status1".
However, if some of these inputs have multiple words such as the following-
| Code: | # echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $i |
fails
Also, "$i", '"$i"' $(<i) ...etc. doesn't work.
Am I missing something or perhaps Xdialog doesn't accept variable input with quoted groups of words?
Cheers,
s
Last edited by seaside on Fri 21 Oct 2011, 12:08; edited 1 time in total
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 18 Oct 2011, 03:39 Post subject:
Re: Xdialog input tags and items |
|
| seaside wrote: | Xdialog has a number of widgets that take variable input in the form of "tag1 item1 status1".
However, if some of these inputs have multiple words such as the following-
| Code: | # echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $i |
fails
Also, "$i", '"$i"' $(<i) ...etc. doesn't work.
Am I missing something or perhaps Xdialog doesn't accept variable input with quoted groups of words?
Cheers,
s | how about
`echo "${i}"`
note that you will have to backslash quotes first
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Tue 18 Oct 2011, 06:00 Post subject:
Subject description: example found on internet |
|
I found this example on the internet.
Hope it helps.
| Code: |
#!/bin/sh
#DIALOG=${DIALOG=dialog}
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
Xdialog --clear --title "My favorite HINDI singer" \
--menu "Hi, Choose your favorite HINDI singer:" 0 0 0 \
"Rafi" "Mohammed Rafi" \
"Mukesh" "Mukesh" \
"Kishore" "Kishore Kumar" \
"Saigal" "K L Saigal" \
"Lata" "Lata Mangeshkar" \
"Yesudas" "K J Yesudas" 2> $tempfile
retval=$?
choice=`cat $tempfile`
case $retval in
0)
echo "'$choice' is your favorite hindi singer";;
1)
echo "Cancel pressed.";;
255)
echo "ESC pressed.";;
esac
|
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Tue 18 Oct 2011, 09:43 Post subject:
|
|
technosaurus,
`echo \"${i}\"`
No, it breaks the line.
8-bit,
Thanks for the example. Unfortunately, the example isn't a variable input being used.
Regards,
s
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 18 Oct 2011, 11:12 Post subject:
|
|
| seaside wrote: | technosaurus,
`echo \"${i}\"`
No, it breaks the line.
8-bit,
Thanks for the example. Unfortunately, the example isn't a variable input being used.
Regards,
s | I meant any quotes inside the variable itself
i='word word word \"set of words\" word word'
... `echo "${i}"`
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Tue 18 Oct 2011, 11:26 Post subject:
|
|
| technosaurus wrote: | I meant any quotes inside the variable itself
i='word word word \"set of words\" word word'
... `echo "${i}"` |
technosaurus,
No, that breaks it also. Darn.
Thanks for the ideas, though.
Regards,
s
EDIT: The following works, but is very difficult to construct.
tag1=431
item="this is one item"
Xdialog --menubox something 0 0 0 $tag1 "$item" $tag1 "$item"
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2675 Location: Kiel,Germany
|
Posted: Tue 18 Oct 2011, 13:06 Post subject:
|
|
Xdialog is like xmessage : a '\'backslash gets printed literally into the gui .
The documentation inside the source does not reveal much about escaping ; just for color variables .
playing around i found this :
echo "tag1 this is the item1" >/tmp/test
Xdialog -menubox "TEST" 0 0 6 "`cat /tmp/test | cut -f 1 -d ' '`" "`cat /tmp/test | cut -f 2-99 -d ' '`"
which would only work for one item .
would need some kind of loop with probably sed -n "$lineNumber p" ....
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Tue 18 Oct 2011, 15:20 Post subject:
|
|
| Karl Godt wrote: | Xdialog is like xmessage : a '\'backslash gets printed literally into the gui .
The documentation inside the source does not reveal much about escaping ; just for color variables .
playing around i found this :
echo "tag1 this is the item1" >/tmp/test
Xdialog -menubox "TEST" 0 0 6 "`cat /tmp/test | cut -f 1 -d ' '`" "`cat /tmp/test | cut -f 2-99 -d ' '`"
which would only work for one item .
would need some kind of loop with probably sed -n "$lineNumber p" .... |
Karl,
Wow - a double cat. I had to stare at that one for a while.
It seems to be doing the same as-
| Code: | | Xdialog --menubox something 0 0 0 $tag1 "$item" $tag1 "$item" | which I mentioned before.
Thanks for checking out the Xdialog source details
Regards,
s
(It seems there should be a simple and less complex solution to this problem - but sometimes not )
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 18 Oct 2011, 16:58 Post subject:
|
|
oops I meant eval, not echo
| Code: | i='Xdialog --infobox "this is an infobox" 0 0'
`eval "${i}"` |
Does anyone else mix up words that start with the same letter?
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Tue 18 Oct 2011, 17:44 Post subject:
|
|
| technosaurus wrote: | oops I meant eval, not echo
| Code: | i='Xdialog --infobox "this is an infobox" 0 0'
`eval "${i}"` |
Does anyone else mix up words that start with the same letter? |
technosaurus,
Thanks for another try but no go. Also infobox doesn't have extra tag item. Needs a solution to -
#echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $????here
Regards,
s
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Tue 18 Oct 2011, 21:03 Post subject:
|
|
I think Xdialog's processing is what is giving you problems.
The syntax of "Xdialog --menubox tag item tag item " is interpreting the string as (this)tag , (is)item, one(tag), (item)item.
I can get it all to display on one line by replacing the space with a period in the string, but it is still splitting the string into a tag-item display.
As in the example I posted, the first name is the tag that gets returned and the second full name is the item that does not.
So the way it is interpreting your string, it returns "this" as the tag and ignores the "is" item.
And it is using the space as a delimiter for the values so the last part of the string is seen by it as another tag-item.
I still do not have an answer for you as to how you would get it to interpret and pass back the entire string when selected.
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Tue 18 Oct 2011, 21:26 Post subject:
|
|
seaside, I am back after following the logic I tried to explain with an example for you to run. The example you can run follows. There is a space between the backslash and the line it follows. Also, the string "this is one item" is actually a tag and the string "and this is another" is actually an item.
| Code: |
#! /bin/bash
i=$tag
#echo $i
Xdialog --menubox something 10 40 0 $i \
"this is one item" "and this is another" \
"tag2 is here" "item 2 is here" \
`eval "${i}"`
|
|
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 834
|
Posted: Tue 18 Oct 2011, 23:06 Post subject:
|
|
| 8-bit wrote: | seaside, I am back after following the logic I tried to explain with an example for you to run. The example you can run follows. There is a space between the backslash and the line it follows. Also, the string "this is one item" is actually a tag and the string "and this is another" is actually an item.
| Code: |
#! /bin/bash
i=$tag
#echo $i
Xdialog --menubox something 10 40 0 $i \
"this is one item" "and this is another" \
"tag2 is here" "item 2 is here" \
`eval "${i}"`
|
|
8-bit,
Thanks for looking at this. The input for Xdialog --menubox is this format.
tag1 item1 tag2 item2 tag3 item3 ......etc
In your example the line pairs are not variables but quoted constants ("tag2 is here" "item 2 is here") . So it can only be used that way for strings that are unchanging.
Whew...this problem seems to resist a reasonable answer. .
Regards,
s
|
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 3843
|
Posted: Tue 18 Oct 2011, 23:08 Post subject:
|
|
| seaside wrote: | | technosaurus wrote: | oops I meant eval, not echo
| Code: | i='Xdialog --infobox "this is an infobox" 0 0'
`eval "${i}"` |
Does anyone else mix up words that start with the same letter? |
technosaurus,
Thanks for another try but no go. Also infobox doesn't have extra tag item. Needs a solution to -
#echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $????here
Regards,
s | you can just keep adding to your variable as necessary
i=${i}' '${PARAM}' 0 0' #add this to what is already in variable "i"....
i=${i}' '${NEWPARAM}' 0 0' #add another one
#.... above could be a loop that tacks on parameters each time
#then run it with:
eval "${i}"
ex.
i='Xdialog --menubox "This is a menubox example" 0 0 3 1 "option 1" 2 "option 2"'
i=$i' 3 "option 3"'
eval $i
_________________ Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
|
|
Back to top
|
|
 |
8-bit

Joined: 03 Apr 2007 Posts: 3012 Location: Oregon
|
Posted: Wed 19 Oct 2011, 00:51 Post subject:
|
|
seaside,
How about another example using variables to hold tag and item strings.
I just modified my fixed string example so anything you put in the variables would display. You do need separate variables for tag and item with it though. When I tried to combine them, the display and output would mess up.
EDIT: If you change the second line to t1="$1" you can even send the t1 variable from the command line by doing Program.sh "Some text".
I have not figured out yet how one gets the item variable passed back as the selection. Currently, the tag variable only gets returned.
So other than the display, the item variable just as well be a dummy.
| Code: |
#! /bin/bash
t1="this is one item"
m1="and this is another"
t2="tag 2 is here"
m2="item 2 is here"
Xdialog --menubox something 10 40 0 $i \
"$t1" "$m1" \
"$t2" "$m2" \
`eval "${i}"`
|
|
|
Back to top
|
|
 |
|