0

I have a made a script on bash.

#!/bin/bash

zen(){
mark=$(zenity --scale \
    --text 'FREQUENCY' \
    --value=$la \
    --min-value=0\
    --max-value=5000 \
    --step=1)
}
la=500

echo "Script for shim. Regulary frequency"
zen
while [ true ] 
do

case $? in

    0) echo $mark
       la=$mark
       #zenity --notification --window-icon="info" --text="Thank you!" --timeout=1
       zen
    ;;
    1) 
       # exit 1
       # sl -e || break
       # break
       # return 1       
    ;;
esac 
done
echo "thanks for using!"

It works okay, excluding exit point. # stands before options I have tried, and every one of them does not allow to exit this script correctly and instead of "thanks for using!" or just nothing I am getting in terminal:

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

^XThis option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

This option is not available. Please see --help for all possible usages.

.........................................

It looks like it is problem with zenity, when I am trying to exit the script. I looked this error up and only sound thought was to upgrade zenity, which I have done but it has given me nothing new...

So how can I solve it and break this script correctly..?

My OS is Ubuntu Server 16.04

EDIT

By my script I would like to achieve repeating question from zenity till the moment when user clicks 'cancel'

  • 1
    This looks terrible. The while [ true ] does work as expected but probably not for the reason you assume. The case $? in refers to the [ true ] and not to the zen. And obviously your zenity call is wrong. – Hauke Laging Aug 8 '17 at 7:51
  • Thanks! It is terrible probably, I am not so sophisticated in bash-programming.. Could you change my script to the correct one? By my script I would like to achieve repeating question from zenity till the moment when user clicks 'cancel' – John Aug 8 '17 at 8:08
  • I can correct the structure but I need to know what the working zenity call looks like. – Hauke Laging Aug 8 '17 at 8:16
  • Call zenity-scale needs for collecting value from scale permanently till user decides to quit and close the window. In working mode script must collect value from zenity-scale and pull them into termnial when user clicks ''Ok' – John Aug 8 '17 at 8:23
3

$? is the exit status of the last command that was run. In your case, that's of the [ command (which you use to test whether the true string is non-empty as a condition of your while loop).

You almost never need to use $? explicitly. Just do

la=500
while
  mark=$(zenity --scale \
      --text 'FREQUENCY' \
      --value="$la" \
      --min-value=0 \
      --max-value=5000 \
      --step=1)
do
  echo "$mark"
  la=$mark
done

Or simply:

mark=500
while
  mark=$(zenity --scale \
      --text 'FREQUENCY' \
      --value="$mark" \
      --min-value=0 \
      --max-value=5000 \
      --step=1)
do
  echo "$mark"
done
0

There is a missing space before the backslash in your zenity call which may cause the error:

zen(){
mark=$(zenity --scale \
    --text FREQUENCY \
    --value=$la \
    --min-value=0 \
    --max-value=5000 \
    --step=1)
}

la=500

echo "Script for shim. Regulary frequency"
zen
zen_ec=$?
while true
do

    case $zen_ec in

        0) echo $mark
           la=$mark
           #zenity --notification --window-icon="info" --text="Thank you!" --timeout=1
           zen
        ;;

[...]
  • Since it's --min-value=0\<newline> --max-value=5000, it should be OK, the \<newline> is removed but that's still --min-value=0 --max-value=5000 so both options are separated (because of the spaces at the start of the --max-value. There are issues with unquoted variables though, and the fact that $? that the OP is checking is the exit status of the [ command, not the zen function. – Stéphane Chazelas Aug 8 '17 at 8:31
  • This code is giving the same result... – John Aug 8 '17 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.