Bash kdialog输入框不结算?来自msgbox的错误回报

时间:2018-11-20 04:40:03

标签: linux bash ubuntu-18.04

我正在使用Ubuntu 18.04在bash中进行编码,并且正在使用kdialog。我制作了一个简单的魔术八球主题程序,但无法关闭输入框并退出该程序,反而陷入了循环。该代码最初是在BASH对话框中制作的,我决定将其更改为kdialog。任何帮助将不胜感激。我忽略了这很简单。

#!/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

1 个答案:

答案 0 :(得分:0)

经过一番睡眠,我轻松地发现了这个问题。我删除了case语句,而使用了if语句。由于kdialog的--msgbox返回0,因此该程序不会脱离case语句。

#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;