Whats wrong with this if-else


 
Thread Tools Search this Thread
# 1  
Whats wrong with this if-else

hi whats wrong in below??

Code:
CHECK=M10;
if [ "$CHECK" = "M9" || "$CHECK" = "M10" || "$CHECK" = "M11" || "$CHECK" = "M12" ];
then
echo "hello hi";
else
echo "how are u hello hi";
fi

I am getting error as

Code:
./test.sh: line 2: [: missing `]'
./test.sh: line 2: M10: command not found
./test.sh: line 2: M10: command not found
./test.sh: line 2: M10: command not found


Last edited by methyl; 12-12-2011 at 01:06 PM.. Reason: please use code tags
# 2  
You can't use || inside [ ]. Use -o.
# 3  
Content delete as already answered

Last edited by frappa; 12-12-2011 at 12:16 PM.. Reason: Content delete as already answered
# 4  
Code:
if [ "$CHECK" = "M9" -o "$CHECK" = "M10" -o "$CHECK" = "M11" -o "$CHECK" = "M12" ];

# 5  
foud the issue

replaced [ with "[[" and ] with "]]"
# 6  
Quote:
Originally Posted by skyineyes
foud the issue

replaced [ with "[[" and ] with "]]"
That's an alternative solution, if your shell supports it.

You gave no information on what your shell was, so I gave you an answer that would work in any shell.

This is why you should always start your post by explaining what your shell and system is...
# 7  
Does that mean "-o" is supported in all shells ???
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #766
Difficulty: Medium
Modern CPUs have multiple non-interacting on-chip caches.
True or False?

10 More Discussions You Might Find Interesting

1. Programming

Whats wrong with this If statement?

Hi I am pretty new to bash scripting.I am trying to write the if statement in bash and it give me error. Can you please help me what I am doing wrong in If statement? Code: if && && then fector=$kk; divide=$DB_SIZE/$kk; echo "factor value:$fector" echo"divide... (1 Reply)
Discussion started by: Gevni
1 Replies

2. Homework & Coursework Questions

Whats wrong with the following

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: ls -ld htdocs drwxr-x--- 3 root root 8192 2006-11-19 10:41 htdocs How would a host administrator... (1 Reply)
Discussion started by: Larry_1
1 Replies

3. Shell Programming and Scripting

Whats wrong with my Loop

Hi all, I have been given a task to search for strings in a file that is encoded. I need to display the file name only when all the 3 strings which i provide are present in the file name. i first try to get a list of files according from the directory according to the value passed in argument... (0 Replies)
Discussion started by: amit1_x
0 Replies

4. UNIX for Dummies Questions & Answers

whats wrong with this?

can anyone tell me why this code doesn't work how its supposed to, its the hangman game but it doesn't play how its supposed to #!/bin/bash NoAttempts="0" livesgiven="5" LivesRemain=$livesgiven LettersAttempted="" wordfile=words numwords=0 function menu() { clear cat << menu... (1 Reply)
Discussion started by: ferrycorsten73
1 Replies

5. Shell Programming and Scripting

Whats wrong with this IF condition?

I have four variables, dumpdata, defndata, compare1 and compare2 I want an IF statement condition which returns true when either dumpdata=defndata or (dumpdata<=compare1 and dumpdata>=compare2). But this is not working for me.. if (4 Replies)
Discussion started by: indianjassi
4 Replies

6. Shell Programming and Scripting

tell me whats wrong with this

#! /bin/bash USAGE=" | ] if then echo "$USAGE" exit 1 fi while getopts lb: OPTION do case $(OPTION)in a) echo Hi there! exit 2;; b) echo hello o) OARG=$OPTARG;; \?)echo "$USAGE" ;; exit 2;; esac done shift `expr... (1 Reply)
Discussion started by: nadman123
1 Replies

7. Shell Programming and Scripting

tell me whats wrong in this?

#! /bin/bash head -5 $1 echo "remove $1 ?" read answer if then echo invalid answer elif rm $1 echo "$1 is deleted" elif then echo file is not deleted else echo "invalid answer" fi What i really want this to do is to ask to delete the file or not..it says something wrong... (1 Reply)
Discussion started by: nadman123
1 Replies

8. Shell Programming and Scripting

Whats wrong with this script?

Hi all, #!/bin/ksh BIN=/interface/Gunner age=$1 directory="$2" && directory=. cd "$directory" || exit 1 from=`$BIN/today -$age` cd $BIN for i in `cat filestoarchive.txt`;do cd $i find . -mtime 14 | grep -v '.tar$' | $BIN/dttmfilter | awk '$1<="'$from'"{ print;};' | \ done (2 Replies)
Discussion started by: kayarsenal
2 Replies

9. Shell Programming and Scripting

Whats wrong with the syntax

Whats wrong with below logic or syntax???? (4 Replies)
Discussion started by: dsravan
4 Replies

10. Shell Programming and Scripting

Whats wrong with the mv command

I am sorry guys I have figured out the error myself. (0 Replies)
Discussion started by: dsravan
0 Replies

Featured Tech Videos