LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 09: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, 09:26 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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 09:35 AM.
 
Old 05-27-2011, 07:20 AM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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



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

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

All times are GMT -5. The time now is 01:23 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
Open Source Consulting | Domain Registration