LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-23-2012, 11:52 AM   #1
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Rep: Reputation: 0
Is command test equivalent to "[]"?


I see example like below, which I thought should be used with test.

Code:
[ $retval -eq 0 ] && echo "$user found" || echo "$user not found"
I checked man test, and it hints test is equivalent to [].

SYNOPSIS
test EXPRESSION
test

[ EXPRESSION ]
[ ]
[ OPTION
 
Old 02-23-2012, 12:04 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
And what happens when you do - man [
 
Old 02-23-2012, 12:09 PM   #3
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by grail View Post
And what happens when you do - man [
Code:
NAME
       test - check file types and compare values

SYNOPSIS
       test EXPRESSION
       test

       [ EXPRESSION ]
       [ ]
       [ OPTION
 
Old 02-23-2012, 12:22 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
To get the help for bash built-ins, use help test etc. The man pages give information about the executables that bash uses as "externals". Mostly they work the same but not always.
 
1 members found this post helpful.
Old 02-23-2012, 12:26 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Try reading info test too.

But catkin is right. bash has it's own internal implementation of test.

And while you're there, also take a look at [[ and ((..)).
 
1 members found this post helpful.
Old 02-23-2012, 12:37 PM   #6
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
To get the help for bash built-ins, use help test etc. The man pages give information about the executables that bash uses as "externals". Mostly they work the same but not always.
Thanks a million. Great to know how to check syntax of built-in commands...
 
Old 02-23-2012, 12:42 PM   #7
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David the H. View Post
Try reading info test too.

But catkin is right. bash has it's own internal implementation of test.

And while you're there, also take a look at [[ and ((..)).
Thank you! It looks like in terms of arguments and return, test and [[ are exchangeable. That pretty answers my question
 
Old 02-23-2012, 12:46 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by johnifanx98 View Post
Thank you! It looks like in terms of arguments and return, test and [[ are exchangeable. That pretty answers my question
Not exactly. test and [ ... ] are interchangeable. [[ ... ]] is the souped-up GT-racing version.
 
Old 02-26-2012, 11:50 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
See here for the differences between [ and [[.

http://mywiki.wooledge.org/BashFAQ/031

((..)) is one technique for arithmetic evaluation, which can be used instead of the regular tests when working with integers.

http://mywiki.wooledge.org/ArithmeticExpression
 
1 members found this post helpful.
  


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
Linux equivalent to DOS "tree" command? XDude Linux - Newbie 10 09-25-2014 01:24 PM
[SOLVED] any linux-desktop equivalent to the "start" command? dombrowsky Linux - Desktop 4 01-16-2010 01:54 AM
SFTP equivalent of FTP's "quot" command. jrobins Linux - Networking 3 10-04-2008 12:29 PM
command in solaris which is equivalent to "smbstatus" of linux Nupur Singh Solaris / OpenSolaris 2 02-02-2006 01:25 PM
Equivalent to Dos "Type" command? greendemon Linux - Newbie 2 08-04-2003 05:48 AM


All times are GMT -5. The time now is 10:46 PM.

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