Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-07-2010, 07:33 AM   #1
LQ Newbie
Registered: Jun 2010
Posts: 18

Rep: Reputation: 0
variable comparison problem in script

Dear all,

In my script ( )I wrote the following to count the filenumber of the current directory and if total file is 6 then run file that contain 'HelloWorld'.

morad=$(ls |wc -l)
if [${morad} -eq 6];

when I run the script, it says that
[oracle@rmancat scr_test]$ ./
./ line 2: [6=6]: command not found

Please help me..

Old 06-07-2010, 07:37 AM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
You need spaces after the [ and before the ] in if [${morad} -eq 6]

BTW, the { and } in ${morad} are not wrong but are not necessary.
Old 06-07-2010, 09:43 AM   #3
LQ Newbie
Registered: Jun 2010
Posts: 18

Original Poster
Rep: Reputation: 0

Thanks CATKIN,

It is working !!!!!

Thanks again....


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
[SOLVED] Problem With Shell Script Variable Usage Crowey Linux - General 2 02-09-2010 02:03 AM
Script to copy specific directory based on variable to folder with that variable name fluxburn Programming 7 01-07-2010 08:59 PM
Problem with bash script - variable name within variable name steven.c.banks Linux - Newbie 3 03-10-2009 04:08 AM
Mysql variable comparison Murdock1979 Programming 2 08-06-2008 05:52 PM
Bash Script Variable Problem jimmy512 Programming 5 05-11-2007 08:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:47 AM.

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