[: ']' missing Error is coming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [: ']' missing Error is coming
# 1  
Old 05-13-2014
[: ']' missing Error is coming

Hi guyz, i m new to UNIX (ksh) shell scripting. while running simple code i m getting error.

Code:
read opt1
read opt2

if [ [ "$opt1" == 1 || "$opt1" == 2 || "$opt1" == 3 ] && [ "$opt2" == "YES" ] ]; then
echo "Yes"
fi

while running i m getting the below error.

Code:
0
YES
./ifelse.ksh[4]: [: ']' missing
./ifelse.ksh[4]: 0: not found [No such file or directory]
./ifelse.ksh[4]: 0: not found [No such file or directory]

Here i want to imply the logic
Code:
if (( a=1 or a=2 or a=3 ) and b=1 ) then

Thanks in advance.

Moderator's Comments:
Mod Comment Use code tags please, see PM.

Last edited by zaxxon; 05-13-2014 at 03:43 AM..
# 2  
Old 05-13-2014
Welcome to the forum.
Use code tags to mark your code.
Try :
Code:
read opt1
read opt2

if  [ "$opt1" == 1 -o "$opt1" == 2 -o "$opt1" == 3 ] && [ "$opt2" == "YES" ] ; then
echo "Yes"
fi

# 3  
Old 05-13-2014
Try:
Code:
if [[ "$opt1" == 1 || "$opt1" == 2 || "$opt1" == 3 ]] && [[ "$opt2" == "YES" ]]; then
  echo "Yes"
fi

or
Code:
if [[ ( $opt1 == 1 || $opt1 == 2 || $opt1 == 3 ) && $opt2 == "YES" ]]; then

or
Code:
if [[ $opt2 == YES && $opt1 == [123] ]]; then

or
Code:
if [[ $opt2 == YES && $opt1 == [1-3] ]]; then

# 4  
Old 05-13-2014
Welcome...
OSX 10.7.5.

Code:
#!/bin/ksh
read opt1
read opt2

if [ "$opt1" == 1 ] || [ "$opt1" == 2 ] || [ "$opt1" == 3 ] && [ "$opt2" == "YES" ] ]; then
echo "Yes"
fi

Results:-
Code:
Last login: Tue May 13 08:05:35 on ttys000
AMIGA:barrywalker~> chmod 755 yn.sh
AMIGA:barrywalker~> ./yn.sh
2
YES
Yes
AMIGA:barrywalker~> ./yn.sh
1
NO
AMIGA:barrywalker~> _

# 5  
Old 05-13-2014
Thanks Everyone...got resolved.

---------- Post updated at 01:07 PM ---------- Previous update was at 01:07 PM ----------

Thanks everyone.it got resolved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Error in ksh script: missing right bracket

I have no idea how to write ksh script, but i'm really in need of help with this. I using fedora 30 and in attempt of runnig attached script i getting those errors, i solved first error by removing excess bracket, but i do not know what should i do with other. Pls sorry for trash post. (8 Replies)
Discussion started by: NullPtr
8 Replies

2. UNIX for Beginners Questions & Answers

Missing argument for option: n Error

I am trying to execute the cli.sh script in another shell script passing arguments and getting the below error. Myscript.sh #!/bin/sh /home/runAJobCli/cli.sh runAJobCli -n $Taskname -t $Tasktype I am passing the below 2 arguments and it giving error ./Myscript.sh T_SAMPLE_TEST MTT... (11 Replies)
Discussion started by: Info_Geek
11 Replies

3. UNIX for Beginners Questions & Answers

Compilation error character is missing-UNIX shell script

Dear Friends, Regarding Compilation error character is missing-unix shell script I am new to unix shell script. My requirement is --I need to find out 3 files in my UBM unix directory,if any one(CMUSER) file is available means,then i need to exit from my unix script, Below is my unix... (2 Replies)
Discussion started by: Joseph2017
2 Replies

4. Shell Programming and Scripting

ERROR: Required Parameters Missing

i have modified a korn shell script to include a parameter and i coded the parameter as pSec=$1 pLoopCnt=$2 wheni run the script it gives me an error $ ksh sfs_pcard_load_file.ksh 30 3 ERROR: Required Parameters Missing. USAGE: sfs_pcard_load_file.ksh please help i think i might... (4 Replies)
Discussion started by: wtolentino
4 Replies

5. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

6. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

7. Shell Programming and Scripting

Missing ] error in csh script

The below script gives error: Missing ] #!/bin/csh set MAX=15 set PATTERN='dtsession' set NUM=`ps -eaf | grep -c $PATTERN` echo "No of dtsession = "$NUM if then echo 'Quota exceeded permissible limit' echo 'sending mail...............' mail hiten.r.chauhan@gmail.com<<EOF ... (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

8. Shell Programming and Scripting

Error : [: missing `]'

Hi, I am attempting to test the input value for an integer. And if the value is not an integer, the intent is to complain about it and exit. Only if I can get past the syntax error, life will be full. # test input to be a number +$'; ] && { echo "Invalid input; Enter an integer..."; exit 2; }... (7 Replies)
Discussion started by: IETF
7 Replies

9. Shell Programming and Scripting

expect 'missing close-brace' error

my expect script fails when it tries to send a password that I have that uses {}'s. Hoping I can correct that. It doesn't complain about the %, #, *, /, ? or ~ characters only the {}'s. #!/usr/bin/expect spawn ssh root@ca199 expect dsa {send... (1 Reply)
Discussion started by: phpfreak
1 Replies

10. Shell Programming and Scripting

Bash script error: missing destination file name operand.

Ok, i've been messing around in debian the past few days, setting up programs like subversion, mysql and logrotate. The purpose of this script is to use subversion to backup the binary logs. It runs in the cron every 2 hours or so (although I can't get my script to run properly atm, which is why... (1 Reply)
Discussion started by: cganly
1 Replies
Login or Register to Ask a Question