LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-30-2018, 04:37 PM   #1
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 18.04
Posts: 24

Rep: Reputation: 1
Zenity If Then syntax


Zenity ver. 3.28.1
Ubuntu 18.04
Python 2.7.15rc1
bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)

Tried many variations on the if then lines.
With the test below, I get:

Choosing Fast:
Code:
Fast
test.sh: 5: [: Fast: unexpected operator
test.sh: 8: [: Fast: unexpected operator
1
Choosing Medium:
Code:
Medium
test.sh: 5: [: Medium: unexpected operator
test.sh: 8: [: Medium: unexpected operator
1
Choosing Slow:
Code:
Slow
test.sh: 5: [: Slow: unexpected operator
test.sh: 8: [: Slow: unexpected operator
1

Code:
#!/bin/bash
ask=$(zenity --title "Transfer Speed" --text "Estimate Speed" --list --radiolist --column "Choice" --column "Speed" True "Fast" False "Medium" False "Slow")
echo $ask
speed=1
  if [ "$ask" == "Medium" ] ; then
     speed=1.5
  fi
  if [ "$ask" == "Slow" ]; then
     speed=2
  fi
echo $speed
Can someone put me right here?

Last edited by Fitch; 12-30-2018 at 05:08 PM.
 
Old 12-30-2018, 05:56 PM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,384

Rep: Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552
test ([ ]) doesn't want ==, just =
see man test
Code:
  if [ "$ask" = "Medium" ] ; then
     speed=1.5
  fi
 
1 members found this post helpful.
Old 12-30-2018, 06:09 PM   #3
Fitch
LQ Newbie
 
Registered: Feb 2011
Location: Edinburgh
Distribution: Ubuntu 18.04
Posts: 24

Original Poster
Rep: Reputation: 1
Thank you.

Works now..

Did you mean man zenity?
 
Old 12-30-2018, 07:29 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,294

Rep: Reputation: 595Reputation: 595Reputation: 595Reputation: 595Reputation: 595Reputation: 595
No.
The [ ] is an alias for the test command.
 
Old 12-30-2018, 07:50 PM   #5
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,384

Rep: Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552Reputation: 1552
Quote:
Originally Posted by Fitch View Post
Thank you.

Works now..

Did you mean man zenity?
No. man test (thanks MadeInGermany).

Your problem had nothing to do with zenity, or with if...then, but with the syntax of the test ([ ]) command. Besides knowing that the == was wrong, another clue is that errors were reported on every line with the bad syntax, no matter which value got assigned to $ask...that's indicative of a syntax error being detected by the parser on lines 5 and 8 rather than a problem with the value in $ask

Last edited by scasey; 12-30-2018 at 07:59 PM.
 
  


Reply

Tags
conditionals, text-fields, zenity


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get zenity code if user close zenity window pedropt Programming 4 03-03-2017 01:13 PM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 01:52 PM
[SOLVED] "Error: syntax before '@' token and Error: syntax at 'OTHER' token" bullrider Programming 2 07-27-2009 09:00 AM
Starting httpd: httpd: Syntax error on line 209 of /etc/httpd/conf/httpd.conf: Syntax sethukpathi Linux - Networking 6 04-12-2008 12:26 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 07:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration