Missing ] error in csh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Missing ] error in csh script
# 1  
Old 02-25-2011
Missing ] error in csh script

The below script gives error: Missing ]

Code:
#!/bin/csh
set MAX=15
set PATTERN='dtsession'
set NUM=`ps -eaf | grep -c $PATTERN`
echo "No of dtsession = "$NUM
if [ "$NUM" -gt "$MAX" ]
then
 echo 'Quota exceeded permissible limit'
 echo 'sending mail...............'
 
 mail hiten.r.chauhan@gmail.com<<EOF
 $NUM is greater than 15
 EOF
 echo 'mail sent..................'
fi

when run
Code:
adroit:/home/seo/hitendra 125 ] unix_5_b.sh
No of dtsession = 44
Missing ].
adroit:/home/seo/hitendra 126 ]

what is the root cause ?

Last edited by hiten.r.chauhan; 02-25-2011 at 05:40 AM.. Reason: problem in giving error
# 2  
Old 02-25-2011
I believe that you need to use ordinary brackets (...) rather than square brackets in C shell scripting
Code:
if ( "$NUM" -gt "$MAX" )

# 3  
Old 02-25-2011
You're mixing CSH syntax with Bourne Shell syntax. Settle for one of them. And seeing as most of your code is Bourne compatible, I'd say go with that (and it's easier to debug too IMO).
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

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

3. Shell Programming and Scripting

If test script error: "Missing ]"

EDIT: Resolved Resolved by changing the first line to bash rather than csh, does bash and csh treat the brackets differently? Hi all, I'm doing to some basic stuff to teach myself "if" I've written the following: #!/bin/csh echo "This script checks for the test file" ... (1 Reply)
Discussion started by: Meshuggener
1 Replies

4. Emergency UNIX and Linux Support

Csh script with Undefined variable error

hi there I have this C shell script that was migrated from AIX to Linux, could someone please help me, I checked the syntax numerous times but I can't find out where the error is. The script is meant to find files older than 27 days and delete it #!/usr/bin/csh # ... (22 Replies)
Discussion started by: hedkandi
22 Replies

5. Shell Programming and Scripting

CSH missing - problem

Hi all, i need help with this code set login = (`cut -d ":" -f1 /etc/passwd.2001`) set group = (`cut -d ":" -f4 /etc/passwd.2001`) set name = (`cut -d ":" -f5 /etc/passwd.2001 | cut -d ":" -f1`) set i = 1 while ($#login > 0) set pom = `last $login | wc -l` if ($pom < 3) then... (1 Reply)
Discussion started by: Casualty
1 Replies

6. Shell Programming and Scripting

csh array missing some elements

I'm having a problem with this bit of my script. '/tmp/data' contains the output of 'ls -l', and I'm assigning a couple of the columns to an array. The problem is that it line starts on the third line of 'ls -l' rather than the first one. @ count = 7 set line = `cat /tmp/data` while ($count... (1 Reply)
Discussion started by: tkirk
1 Replies

7. Shell Programming and Scripting

Undefined variable error in csh script

Below csh script gives error: Undefined variable:confused: #!/bin/csh $QUERY="netscape"; COUNT_NETSCAPE=${ps | grep -c $QUERY}; echo $COUNT_NETSCAPE; when run gives error adroit:/home/seo/hitendra 64 ] ./unix_6.sh QUERY: Undefined variable. What is the root cause of the... (3 Replies)
Discussion started by: hiten.r.chauhan
3 Replies

8. 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

9. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

10. Shell Programming and Scripting

CSH Error Message

Hi, I am new to unix, and trying to create a simple script called "nightjobs" set TODAY=`date +"%m%d%y"` echo -n "Please enter your Initials (3 alpha characters): " read init for GROUP in 4 5 do set logfile="/home/OPER/LOGS/nightjobs"$GROUP"-TODAY".log" set... (6 Replies)
Discussion started by: Latha Nair
6 Replies
Login or Register to Ask a Question