"binary operator exected" problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers "binary operator exected" problem
# 1  
Old 04-02-2011
MySQL "binary operator exected" problem

Hey guys/gals,

Am having trouble getting an 'if statement' to play nice..


I am playing with a script and need 'if' to check whether "y" or "Y" has been
entered and if not to exit.
In previous scripts I was playing with there would normally be a Y and a N response
possibility so each response would have their own 'then statement'.

In this case I want to ensure that if neither y or Y is entered that the scriupt exits.

I was hoping to get away with ;
Code:
echo -ne "the question requiring the y/n response ; "
read input
if [ "$input" != "y" ] || [ "$input" != "Y" ] ; then 
echo "blah blah" 
exit
fi

But no dice Smilie

I have tried using '-ne' but also no luck, using '!==' results in a binary operator expected error..
Just can' t seem to get it to do what I would like.

Any ideas on how best to get 'if' to confirm that the input is NOT the desired input ?

Many thanks !

Last edited by TAPE; 04-02-2011 at 08:21 AM..
# 2  
Old 04-02-2011
The problem is in [ "$input" != "y" ] || [ "$input" != "Y" ], it will always true.

if you input y, the second condition is trun, if you input Y, the first condition is trun, if you input N or n or other words, both conditions are true.

Code:
echo -ne "the question requiring the y/n response ; "
read input
if [ "$input" == "y" ] || [ "$input" == "Y" ] ; then
  echo "Good"
else
  echo "blah blah"
exit
fi

# 3  
Old 04-02-2011
Ah, that does makes perfect sense.. my mind is obviously not functioning right just yet Smilie

Will play some more, thanks for your prompt response rdcwayx !
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

3. Shell Programming and Scripting

What "-a" operator means in "if" statement

Hi I am trying to figure out what the following line does, I work in ksh88: ] && LIST="$big $LIST" Not sure what "-a" means in that case. Thanks a lot for any advice -A (1 Reply)
Discussion started by: aoussenko
1 Replies

4. Shell Programming and Scripting

cannot properly employ "or" operator in an if statement (bash)

Hi, I have a variable, $sername, and I would like to display this variable only if it *does not* contain either of these two tags: *DTI*FA* or *DIFF*FA*. I think the syntax for my 'or' operator is off. The variable $sername is continuously changing in an outer loop (not shown), but at the... (4 Replies)
Discussion started by: goodbenito
4 Replies

5. Shell Programming and Scripting

error "test: [-d: unary operator expected" very confused.

Im trying to check if a series of directory exists and if not create them, and am having issues. All the instances of test return with the error "test: #!/bin/bash location_Parent=~/Documents/sight_of_sound location_IMG=~/Documents/Sight_of_sound/IMG location_AUD=~/Documents/Sight_of_sound/AUD... (4 Replies)
Discussion started by: orionrush
4 Replies

6. Shell Programming and Scripting

How can I use a pipe operator in a variable: OPTION="| command"?

I have a string of commands I am piping some data through and I want to allow command line switches to select which commands are used. I want to do something like this: OPTION="| command3" command1 -a -b c.txt | command2 -d -e $OPTION >result.txt I want to do it that way because OPTION may be... (1 Reply)
Discussion started by: KenJackson
1 Replies

7. UNIX for Advanced & Expert Users

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have a problem about the Oracle related components. I'm not able to find any answer yet, and waiting for your responses... Here is the configuration of my system: * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or... (1 Reply)
Discussion started by: talipk
1 Replies

8. UNIX and Linux Applications

A question/problem about oracle "tns listener" and "enterprise manager"

hi, I have * an IBM P550 machine, * an AIX 5.3 running on it and * an oracle database, already installed on it. The problem (or question of my own) is: Oracle tns listener, "CT_LISTENER", and the enterprise manager (EM) of the instance, which is uniq instance and called... (0 Replies)
Discussion started by: talipk
0 Replies

9. Shell Programming and Scripting

awk returning "[: ==: unary operator expected"

Hi All, I am new to shell scripting and right now I am just limited to using the pre-written scripts. I am in to Infrastructure management where we use different scripts to get the information passed on to the monitoring tools. I am trying to use this script to get the information about the... (2 Replies)
Discussion started by: theamrit
2 Replies

10. Linux

missing binary operator before token "("

Hello every one, how are u doing? my macine has following os: ===================== Linux 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux here i am trying to compile a c++ project.i am getting the following error. error: ======= Generating... (4 Replies)
Discussion started by: mannam srinivas
4 Replies
Login or Register to Ask a Question