LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2011, 10:05 AM   #1
hd_pulse
Member
 
Registered: Dec 2010
Posts: 35

Rep: Reputation: 0
Error: ./10aa: line 5: [-n: command not found 127


Quote:

#Taking Decisions
#Usuage:10aa
a="300"
[-n $a]
echo $?

Please explain the error??
 
Old 05-25-2011, 10:26 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
It's usually helpful to give some background about what you're trying to do. Asking direct questions without any context can come across as a bit rude.

Anyway...

http://mywiki.wooledge.org/BashPitfa...22.24foo.22.5D

"[" is a command (a synonym for test), and everything that follows it is an argument to that command. This means that each argument has to separated by at least one space.

Code:
[ -n "$a" ]
You should also get in the habit of quoting variables inside them to avoid word splitting.

http://mywiki.wooledge.org/BashPitfa...22.24foo.22.5D

Edit: and in this case it's absolutely necessary. If the variable were null, then after variable substitution the unquoted test would become simply [ -n ], and you'd be testing nothing (or perhaps the literal string "-n", I'm not sure), rather than a null string. In any case, test evaluates it as true.

Also consider using bash's [[..]] extended test keyword or the ((..)) arithmetic function instead.
http://mywiki.wooledge.org/BashFAQ/031
http://mywiki.wooledge.org/ArithmeticExpression

Last edited by David the H.; 05-25-2011 at 10:35 AM.
 
Old 05-27-2011, 08:20 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
It's also considered respectful to post a reply of some kind when someone has taken the time to help you. A "thank you" should be given at a minimum, and even better would be to follow it up with a few direct comments on what was written, to demonstrate that it was read, comprehended, and found useful.

You know, actually discuss the topic.
 
  


Reply


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
make: CC: Command not found make: *** [main.o] Error 127 on opensuse 11.3 Leo89 Linux - Newbie 6 11-30-2012 06:13 PM
make: ifort: command not found ERROR 127 alismu Linux - Newbie 1 02-27-2010 03:04 AM
Unable to compile C++ programs.make:g++ command not found error.Error 127 PrathuD Programming 3 03-16-2009 01:44 PM
roo tail, make Error 127, /bin/sh: rman: command not found DraaX Linux - Desktop 4 08-28-2006 10:57 PM
make: Command not found, Error 127. I'm on Redhat Arild2 Linux - Newbie 3 10-30-2004 02:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:30 AM.

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