bash kdialog messages - kde - explaing how line works

I’ve read about this on webpages. I still can’t make logical sense of it. Do I need to fix this? What does this output mean? If yes, how do I fix it.

Menu_Select=$(kdialog --radiolist "SCANVIRUS:  Main Menu" 1 "Scan Systems" on 2 "Scanlog Menu" off 3 "View Menu" off 4 " " off 5 "Kill All Scans" off 6 " " off 7 "Show Help Menu" off)
No protocol specified
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

Can someone explain to me how this line works? Unlike the above, it doesn’t return a value, yet It returns a value using this format. Remove ‘&& echo 1’ and it will not return a value.

Menu_Select=$(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans" && echo 1)

I’m still stuck and getting nowhere. Need help.

Hi,

I’m not perfectly sure, but I’ll try a guess.

kdialog --radiolist and --yesno return different types of values. The first line works perfercly in the shell:

kasi@pluto:~/Schreibtisch> Menu_Select=$(kdialog --radiolist "SCANVIRUS:  Main Menu" 1 "Scan Systems" on 2 "Scanlog Menu" off 3 "View Menu" off 4 " " off 5 "Kill Al Scans" off 6 " " off 7 "Show Help Menu" off) 
kasi@pluto:~/Schreibtisch> echo $Menu_Select 
5

kdialog returns the value 5 after selecting the “Kill Al” and applies it to the variable Menu_Select.
Not sure where the error messages in your example are coming from, probably from somewhere else in your script.

kdialog --yesno just returns a boolean, I suppose. && is a logical AND. It will process the second command only if the first one finishes successfully without an “error”, resp. with a 0. So, when hitting “yes” the echo command will be processed and the result applied to the variable. I chose a different one for this example:

kasi@pluto:~> onkel=$(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans" && echo 1) # then hit "yes"
kasi@pluto:~> echo $onkel
1
kasi@pluto:~> onkel=$(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans" && echo 1) # then hit "no"
kasi@pluto:~> echo $onkel

kasi@pluto:~> onkel=$(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans" && echo 42) # then hit "yes"
kasi@pluto:~> echo $onkel
42
kasi@pluto:~> #and so on...

Did I get your issue?
Cheers!

kasi

I didn’t explain clear enough. So, again.

Menu_Select=$(kdialog --radiolist "SCANVIRUS:  Main Menu" 1 "Scan Systems" on 2 "Scanlog Menu" off 3 "View Menu" off 4 " " off 5 "Kill All Scans" off 6 " " off 7 "Show Help Menu" off)
-->No protocol specified
-->QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
-->QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

I’v searched for those messages. I can’t find a clear answer on what they are or how to fix them.

# echo $(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans")
No protocol specified
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

There is no returned number on selecting ‘no’.

# echo $(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans")
No protocol specified
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

There is no returned number on selecting 'yes". It should return ‘1’(or some value).

This is a bug in the function. All other functions return a value

echo $(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans" && echo 1)
No protocol specified
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

Press ‘no’, returns nothing.

# echo $(kdialog --title "SCANVIRUS:  Main Menu" --yesno "Kill All Scans" && echo 1)
No protocol specified
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
1

Press ‘Yes’, returns nothing.

You have to add the ‘&& echo 1’ to make it work. This is either design flaw or bug in this function.

kdialog failed to connect to X server. Likely because you run it from su or sudo session.

This is either design flaw or bug in this function.

Of course, everything that you do not understand is a bug.

kdialog is documented pretty well. Have you tried to actually read it?

-radiolist and -checklist(and others) work as they should. Reading the docs on the kde manual page is how I was able write the rest of the code.

You still haven’t answered why the function needs ‘&& echo 1’. The other two don’t need it. This is clearly a design flaw in the function that makes it harder to use and understand. That part of the line shouldn’t be needed.

It should be this:

cancel/close x=-1(also null string)
yes=0
no=1

Based on a normal bash function.

I can bypass this by using the other functions. I’m trying to make the code as readable as possible.

Because you wrote it this way. Nothing prevents you from checking exit code directly.

Actually, the --yesno does return (correct) values:

kasi@pluto:~> kdialog --yesno "hello world" ; echo $? # hit yes 
0 
kasi@pluto:~> kdialog --yesno "hello world" ; echo $? # hit no 
1 
kasi@pluto:~> kdialog --yesno "hello world" ; echo $? # hit esc 
2

But it seems they can’t be read directly in the function. So a little more code may be required.

https://mostlylinux.wordpress.com/bashscripting/kdialog/#yes-no

You can use the 0 or not-0 of the return code directly.

kdialog --yesno "hello world" && echo OK