Bash kdialog Input Box Not Clossing? Possible bad return from msgbox












0















I am coding in bash ,using Ubuntu 18.04, and I am playing around with kdialog. I made a simple magic eight ball themed program and I am unable to close the input box and exit the program, instead I get stuck in a loop. This code was originally made in BASH dialog and I decided to change it to kdialog. Any help would be greatly appreciated. It is something simple that I am overlooking.



#!/bin/bash
#version 3

OUTPUT="TEMP.txt"
>$OUTPUT

while [ true ]
do

shuffle() {
local i tmp size max rand
size=${#array[*]}
max=$(( 32768 / size * size ))

for ((i=size-1; i>0; i--));
do
while (( (rand=$RANDOM) >= max ));
do :;
done
rand=$(( rand % (i+1) ))
tmp=${array[i]}
array[i]=${array[rand]}
array[rand]=$tmp
done
}

array=( 'It Is Certain'
'Without A Doubt'
'Maybe'
'Signs Point To Yes'
'Most Likely'
'As I See It, Yes'
'Ask Again Later'
'Concentrate And Ask Again'
'HAHAH No..'
'Ask Again'
'Have Faith In Yourself'
'Very Doubtful'
'Outlook Not So Good'
'My Sources Say No'
'Unknown At This Time'
'Could Happen Any Moment Now'
'Is That A Joke?'
'Unlikely' )

shuffle

function sayhello(){
local n=${array[@]}-""
#display it
kdialog --msgbox "This Is What I See: ${array}"
#--clear --msgbox "${array}" 8 41
}



# show an inputbox
kdialog --title "Welcome "
--inputbox "Ask and you shall recieve great fortune: " #8 60

function think_tank(){
progress=$(kdialog --progressbar "hmmm Let Me Think..." 4);
sleep 1;
qdbus $progress Set "" value 1 > /dev/null;
sleep 1;
qdbus $progress Set "" value 2 > /dev/null;
sleep 1;
qdbus $progress Set "" value 3 > /dev/null;
sleep 1;
qdbus $progress Set "" value 4 > /dev/null;
sleep 1;
qdbus $progress close > /dev/null;
sleep 1
#kdialog --title "This is a passive popup" --passivepopup
#"It will disappear in about 10 seconds" 10

}
# get response
response=$?

# get data stored in $OUPUT using input redirection
name=$(<$OUTPUT)

case $response in
0)
think_tank
sayhello ${array[@]}
;;
1)
echo "Goodbye For Now."
exit 0
;;
255)
echo "Goodbye For Now."
exit 0
;;
esac

#rm $OUTPUT
done
done









share|improve this question























  • This might help: shellcheck.net

    – Cyrus
    Nov 20 '18 at 5:14
















0















I am coding in bash ,using Ubuntu 18.04, and I am playing around with kdialog. I made a simple magic eight ball themed program and I am unable to close the input box and exit the program, instead I get stuck in a loop. This code was originally made in BASH dialog and I decided to change it to kdialog. Any help would be greatly appreciated. It is something simple that I am overlooking.



#!/bin/bash
#version 3

OUTPUT="TEMP.txt"
>$OUTPUT

while [ true ]
do

shuffle() {
local i tmp size max rand
size=${#array[*]}
max=$(( 32768 / size * size ))

for ((i=size-1; i>0; i--));
do
while (( (rand=$RANDOM) >= max ));
do :;
done
rand=$(( rand % (i+1) ))
tmp=${array[i]}
array[i]=${array[rand]}
array[rand]=$tmp
done
}

array=( 'It Is Certain'
'Without A Doubt'
'Maybe'
'Signs Point To Yes'
'Most Likely'
'As I See It, Yes'
'Ask Again Later'
'Concentrate And Ask Again'
'HAHAH No..'
'Ask Again'
'Have Faith In Yourself'
'Very Doubtful'
'Outlook Not So Good'
'My Sources Say No'
'Unknown At This Time'
'Could Happen Any Moment Now'
'Is That A Joke?'
'Unlikely' )

shuffle

function sayhello(){
local n=${array[@]}-""
#display it
kdialog --msgbox "This Is What I See: ${array}"
#--clear --msgbox "${array}" 8 41
}



# show an inputbox
kdialog --title "Welcome "
--inputbox "Ask and you shall recieve great fortune: " #8 60

function think_tank(){
progress=$(kdialog --progressbar "hmmm Let Me Think..." 4);
sleep 1;
qdbus $progress Set "" value 1 > /dev/null;
sleep 1;
qdbus $progress Set "" value 2 > /dev/null;
sleep 1;
qdbus $progress Set "" value 3 > /dev/null;
sleep 1;
qdbus $progress Set "" value 4 > /dev/null;
sleep 1;
qdbus $progress close > /dev/null;
sleep 1
#kdialog --title "This is a passive popup" --passivepopup
#"It will disappear in about 10 seconds" 10

}
# get response
response=$?

# get data stored in $OUPUT using input redirection
name=$(<$OUTPUT)

case $response in
0)
think_tank
sayhello ${array[@]}
;;
1)
echo "Goodbye For Now."
exit 0
;;
255)
echo "Goodbye For Now."
exit 0
;;
esac

#rm $OUTPUT
done
done









share|improve this question























  • This might help: shellcheck.net

    – Cyrus
    Nov 20 '18 at 5:14














0












0








0








I am coding in bash ,using Ubuntu 18.04, and I am playing around with kdialog. I made a simple magic eight ball themed program and I am unable to close the input box and exit the program, instead I get stuck in a loop. This code was originally made in BASH dialog and I decided to change it to kdialog. Any help would be greatly appreciated. It is something simple that I am overlooking.



#!/bin/bash
#version 3

OUTPUT="TEMP.txt"
>$OUTPUT

while [ true ]
do

shuffle() {
local i tmp size max rand
size=${#array[*]}
max=$(( 32768 / size * size ))

for ((i=size-1; i>0; i--));
do
while (( (rand=$RANDOM) >= max ));
do :;
done
rand=$(( rand % (i+1) ))
tmp=${array[i]}
array[i]=${array[rand]}
array[rand]=$tmp
done
}

array=( 'It Is Certain'
'Without A Doubt'
'Maybe'
'Signs Point To Yes'
'Most Likely'
'As I See It, Yes'
'Ask Again Later'
'Concentrate And Ask Again'
'HAHAH No..'
'Ask Again'
'Have Faith In Yourself'
'Very Doubtful'
'Outlook Not So Good'
'My Sources Say No'
'Unknown At This Time'
'Could Happen Any Moment Now'
'Is That A Joke?'
'Unlikely' )

shuffle

function sayhello(){
local n=${array[@]}-""
#display it
kdialog --msgbox "This Is What I See: ${array}"
#--clear --msgbox "${array}" 8 41
}



# show an inputbox
kdialog --title "Welcome "
--inputbox "Ask and you shall recieve great fortune: " #8 60

function think_tank(){
progress=$(kdialog --progressbar "hmmm Let Me Think..." 4);
sleep 1;
qdbus $progress Set "" value 1 > /dev/null;
sleep 1;
qdbus $progress Set "" value 2 > /dev/null;
sleep 1;
qdbus $progress Set "" value 3 > /dev/null;
sleep 1;
qdbus $progress Set "" value 4 > /dev/null;
sleep 1;
qdbus $progress close > /dev/null;
sleep 1
#kdialog --title "This is a passive popup" --passivepopup
#"It will disappear in about 10 seconds" 10

}
# get response
response=$?

# get data stored in $OUPUT using input redirection
name=$(<$OUTPUT)

case $response in
0)
think_tank
sayhello ${array[@]}
;;
1)
echo "Goodbye For Now."
exit 0
;;
255)
echo "Goodbye For Now."
exit 0
;;
esac

#rm $OUTPUT
done
done









share|improve this question














I am coding in bash ,using Ubuntu 18.04, and I am playing around with kdialog. I made a simple magic eight ball themed program and I am unable to close the input box and exit the program, instead I get stuck in a loop. This code was originally made in BASH dialog and I decided to change it to kdialog. Any help would be greatly appreciated. It is something simple that I am overlooking.



#!/bin/bash
#version 3

OUTPUT="TEMP.txt"
>$OUTPUT

while [ true ]
do

shuffle() {
local i tmp size max rand
size=${#array[*]}
max=$(( 32768 / size * size ))

for ((i=size-1; i>0; i--));
do
while (( (rand=$RANDOM) >= max ));
do :;
done
rand=$(( rand % (i+1) ))
tmp=${array[i]}
array[i]=${array[rand]}
array[rand]=$tmp
done
}

array=( 'It Is Certain'
'Without A Doubt'
'Maybe'
'Signs Point To Yes'
'Most Likely'
'As I See It, Yes'
'Ask Again Later'
'Concentrate And Ask Again'
'HAHAH No..'
'Ask Again'
'Have Faith In Yourself'
'Very Doubtful'
'Outlook Not So Good'
'My Sources Say No'
'Unknown At This Time'
'Could Happen Any Moment Now'
'Is That A Joke?'
'Unlikely' )

shuffle

function sayhello(){
local n=${array[@]}-""
#display it
kdialog --msgbox "This Is What I See: ${array}"
#--clear --msgbox "${array}" 8 41
}



# show an inputbox
kdialog --title "Welcome "
--inputbox "Ask and you shall recieve great fortune: " #8 60

function think_tank(){
progress=$(kdialog --progressbar "hmmm Let Me Think..." 4);
sleep 1;
qdbus $progress Set "" value 1 > /dev/null;
sleep 1;
qdbus $progress Set "" value 2 > /dev/null;
sleep 1;
qdbus $progress Set "" value 3 > /dev/null;
sleep 1;
qdbus $progress Set "" value 4 > /dev/null;
sleep 1;
qdbus $progress close > /dev/null;
sleep 1
#kdialog --title "This is a passive popup" --passivepopup
#"It will disappear in about 10 seconds" 10

}
# get response
response=$?

# get data stored in $OUPUT using input redirection
name=$(<$OUTPUT)

case $response in
0)
think_tank
sayhello ${array[@]}
;;
1)
echo "Goodbye For Now."
exit 0
;;
255)
echo "Goodbye For Now."
exit 0
;;
esac

#rm $OUTPUT
done
done






linux bash ubuntu-18.04






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 4:40









Daniel BradfordDaniel Bradford

42




42













  • This might help: shellcheck.net

    – Cyrus
    Nov 20 '18 at 5:14



















  • This might help: shellcheck.net

    – Cyrus
    Nov 20 '18 at 5:14

















This might help: shellcheck.net

– Cyrus
Nov 20 '18 at 5:14





This might help: shellcheck.net

– Cyrus
Nov 20 '18 at 5:14












1 Answer
1






active

oldest

votes


















0














After some sleep I easily figured this issue out. I removed the case statement and used if statements instead. The program would not break out of the case statement due to a return 0 from kdialog's --msgbox.



#made some quick msgbox functions 
if [ "$?" = 0 ];
then
think_tank #progress bar
msg_box #results
elif [ "$?" = 1 ];
then
goodbye #closing message box
exit 0;
else
error #error message box
exit 0;
fi;





share|improve this answer
























  • This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

    – tripleee
    Nov 21 '18 at 5:52











  • It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

    – Daniel Bradford
    Nov 21 '18 at 6:17











  • Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

    – tripleee
    Nov 21 '18 at 6:39











  • I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

    – Daniel Bradford
    Nov 21 '18 at 19:06











  • All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

    – tripleee
    Nov 22 '18 at 5:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386352%2fbash-kdialog-input-box-not-clossing-possible-bad-return-from-msgbox%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














After some sleep I easily figured this issue out. I removed the case statement and used if statements instead. The program would not break out of the case statement due to a return 0 from kdialog's --msgbox.



#made some quick msgbox functions 
if [ "$?" = 0 ];
then
think_tank #progress bar
msg_box #results
elif [ "$?" = 1 ];
then
goodbye #closing message box
exit 0;
else
error #error message box
exit 0;
fi;





share|improve this answer
























  • This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

    – tripleee
    Nov 21 '18 at 5:52











  • It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

    – Daniel Bradford
    Nov 21 '18 at 6:17











  • Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

    – tripleee
    Nov 21 '18 at 6:39











  • I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

    – Daniel Bradford
    Nov 21 '18 at 19:06











  • All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

    – tripleee
    Nov 22 '18 at 5:23
















0














After some sleep I easily figured this issue out. I removed the case statement and used if statements instead. The program would not break out of the case statement due to a return 0 from kdialog's --msgbox.



#made some quick msgbox functions 
if [ "$?" = 0 ];
then
think_tank #progress bar
msg_box #results
elif [ "$?" = 1 ];
then
goodbye #closing message box
exit 0;
else
error #error message box
exit 0;
fi;





share|improve this answer
























  • This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

    – tripleee
    Nov 21 '18 at 5:52











  • It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

    – Daniel Bradford
    Nov 21 '18 at 6:17











  • Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

    – tripleee
    Nov 21 '18 at 6:39











  • I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

    – Daniel Bradford
    Nov 21 '18 at 19:06











  • All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

    – tripleee
    Nov 22 '18 at 5:23














0












0








0







After some sleep I easily figured this issue out. I removed the case statement and used if statements instead. The program would not break out of the case statement due to a return 0 from kdialog's --msgbox.



#made some quick msgbox functions 
if [ "$?" = 0 ];
then
think_tank #progress bar
msg_box #results
elif [ "$?" = 1 ];
then
goodbye #closing message box
exit 0;
else
error #error message box
exit 0;
fi;





share|improve this answer













After some sleep I easily figured this issue out. I removed the case statement and used if statements instead. The program would not break out of the case statement due to a return 0 from kdialog's --msgbox.



#made some quick msgbox functions 
if [ "$?" = 0 ];
then
think_tank #progress bar
msg_box #results
elif [ "$?" = 1 ];
then
goodbye #closing message box
exit 0;
else
error #error message box
exit 0;
fi;






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 5:44









Daniel BradfordDaniel Bradford

42




42













  • This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

    – tripleee
    Nov 21 '18 at 5:52











  • It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

    – Daniel Bradford
    Nov 21 '18 at 6:17











  • Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

    – tripleee
    Nov 21 '18 at 6:39











  • I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

    – Daniel Bradford
    Nov 21 '18 at 19:06











  • All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

    – tripleee
    Nov 22 '18 at 5:23



















  • This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

    – tripleee
    Nov 21 '18 at 5:52











  • It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

    – Daniel Bradford
    Nov 21 '18 at 6:17











  • Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

    – tripleee
    Nov 21 '18 at 6:39











  • I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

    – Daniel Bradford
    Nov 21 '18 at 19:06











  • All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

    – tripleee
    Nov 22 '18 at 5:23

















This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

– tripleee
Nov 21 '18 at 5:52





This doesn't particularly make sense. You seem to be examining the $? from a different program than you intend.

– tripleee
Nov 21 '18 at 5:52













It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

– Daniel Bradford
Nov 21 '18 at 6:17





It is working like it should for what I wanted. For this case it doesn't matter what the inputs are by the user and the '$?' is just keeping track of the msgbox statuses. Closing the box or exiting out returns a 1.

– Daniel Bradford
Nov 21 '18 at 6:17













Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

– tripleee
Nov 21 '18 at 6:39





Yes, but after the first if, the value in $? corresponds to the value of the command after the if. Try it: sh -c 'exit 2'; if [ $? -eq 0 ]; then echo success; elif [ $? -eq 1 ]; then echo one; else echo $?; fi prints one

– tripleee
Nov 21 '18 at 6:39













I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

– Daniel Bradford
Nov 21 '18 at 19:06





I see what your saying and please correct me if I am wrong, I found through the --man page that the --msgbox returns a 0 value. That is how I stay in my loop until I want to close the program. It loops through each box and closes properly now, there is a while loop that encompasses the entire code. I can post the finished code if you'd like.

– Daniel Bradford
Nov 21 '18 at 19:06













All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

– tripleee
Nov 22 '18 at 5:23





All I'm trying to say is that replacing the case statement was not an improvement, and that one of the code paths here will never execute, and thus can be removed if you don't regard that as a bug.

– tripleee
Nov 22 '18 at 5:23




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386352%2fbash-kdialog-input-box-not-clossing-possible-bad-return-from-msgbox%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)