Results 1 to 9 of 9

Thread: bash kdialog messages - kde - explaing how line works

  1. #1

    Default 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.

    Code:
    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.


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

  2. #2

    Default Re: bash kdialog messages - kde - explaing how line works

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

  3. #3
    Join Date
    Jun 2011
    Location
    Germany
    Posts
    290

    Default Re: bash kdialog messages - kde - explaing how line works

    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:

    Code:
    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:
    Code:
    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

  4. #4

    Default Re: bash kdialog messages - kde - explaing how line works

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

    Code:
    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.



    Code:
    # 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'.

    Code:
    # 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



    Code:
    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.

    Code:
    # 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.

  5. #5
    Join Date
    Sep 2012
    Posts
    6,369

    Default Re: bash kdialog messages - kde - explaing how line works

    Quote Originally Posted by lord_valarian View Post
    Code:
    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
    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?

  6. #6

    Default Re: bash kdialog messages - kde - explaing how line works

    Quote Originally Posted by arvidjaar View Post
    kdialog failed to connect to X server. Likely because you run it from su or sudo session.

    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.

  7. #7
    Join Date
    Sep 2012
    Posts
    6,369

    Default Re: bash kdialog messages - kde - explaing how line works

    Quote Originally Posted by lord_valarian View Post
    You still haven't answered why the function needs '&& echo 1'.
    Because you wrote it this way. Nothing prevents you from checking exit code directly.

  8. #8
    Join Date
    Jun 2011
    Location
    Germany
    Posts
    290

    Default Re: bash kdialog messages - kde - explaing how line works

    Actually, the --yesno does return (correct) values:
    Code:
    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/ba...dialog/#yes-no

  9. #9
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    28,399

    Default Re: bash kdialog messages - kde - explaing how line works

    Quote Originally Posted by kasi042 View Post
    Actually, the --yesno does return (correct) values:
    You can use the 0 or not-0 of the return code directly.
    Code:
    kdialog --yesno "hello world" && echo OK
    Henk van Velden

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •