Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-20-2014, 04:39 AM
|
#1
|
Member
Registered: Oct 2014
Posts: 178
Rep: 
|
explain file in /bin
slack 14.1
ls /bin/
shows a file.. (literally) '['
Second file, after the symlink to 'Mail' and before 'arch'
What is this file?
Executable, but does nothing.
Looks evil.
Does it have a valid purpose?
ls -l /bin
total 10784
lrwxrwxrwx 1 root root 14 Dec 3 2013 Mail -> /usr/bin/mailx*
-rwxr-xr-x 1 root root 36648 Feb 26 2013 [*
-rwxr-xr-x 1 root root 6896 Aug 7 2013 arch*
lrwxrwxrwx 1 root root 4 Dec 3 2013 awk -> gawk*
-rwxr-xr-x 1 root root 33512 Feb 26 2013 base64*
-rwxr-xr-x 1 root root 28008 Feb 26 2013 basename*
-rwxr-xr-x 1 root root 973688 Sep 26 15:05 bash*
..
|
|
|
10-20-2014, 04:48 AM
|
#2
|
LQ Guru
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,584
|
It's part of coreutils.
[ - A synonym for test; this program permits expressions like [ expression ].
|
|
3 members found this post helpful.
|
10-20-2014, 04:57 AM
|
#3
|
Member
Registered: Oct 2014
Posts: 178
Original Poster
Rep: 
|
Learn something new every day..
Thanks.
|
|
|
10-20-2014, 06:31 AM
|
#4
|
Senior Member
Registered: Jan 2011
Location: Oslo, Norway
Distribution: Slackware
Posts: 2,559
|
Next time you want to know from which package a binary or library comes grep /var/log/packages, e.g.
Code:
$ grep -F "bin/[" /var/log/packages/*
/var/log/packages/coreutils-8.19-i486-1:bin/[
|
|
4 members found this post helpful.
|
10-20-2014, 07:06 AM
|
#5
|
Member
Registered: Nov 2005
Location: Land of Linux :: Finland
Distribution: EndeavourOS :: Garuda Linux
Posts: 847
|
i remember first time i saw it, i was kinda sure i was compromised / one of my scripts were malfunctioning and created it. that was several years ago.
|
|
|
10-20-2014, 07:11 AM
|
#6
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,676
|
it still has a man page.
|
|
|
10-20-2014, 11:06 AM
|
#7
|
Member
Registered: Aug 2007
Distribution: Slackware64 13.37
Posts: 215
Rep:
|
I don't have a man page for it here.
But I'm running Slackware64 14.0. Maybe that's why?
|
|
|
10-20-2014, 04:15 PM
|
#8
|
Member
Registered: Feb 2011
Location: England
Distribution: Slackware
Posts: 164
Rep:
|
My -current also has no manpage, although there is of course a manpage for test.
|
|
|
10-20-2014, 10:13 PM
|
#9
|
Member
Registered: May 2007
Posts: 781
|
It's a bash built-in: do 'help [' and you'll get a complete description. The /bin program is for some other context?
|
|
1 members found this post helpful.
|
10-20-2014, 11:47 PM
|
#10
|
LQ Guru
Registered: Aug 2004
Location: Pisa, Italy
Distribution: Slackware
Posts: 7,645
|
Code:
$ /bin/[ --help
Usage: test EXPRESSION
or: test
or: [ EXPRESSION ]
or: [ ]
or: [ OPTION
Exit with the status determined by EXPRESSION.
--help display this help and exit
--version output version information and exit
An omitted EXPRESSION defaults to false. Otherwise,
EXPRESSION is true or false and sets exit status. It is one of:
( EXPRESSION ) EXPRESSION is true
! EXPRESSION EXPRESSION is false
EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true
EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true
-n STRING the length of STRING is nonzero
STRING equivalent to -n STRING
-z STRING the length of STRING is zero
STRING1 = STRING2 the strings are equal
STRING1 != STRING2 the strings are not equal
INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2
INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2
INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2
INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2
FILE1 -ef FILE2 FILE1 and FILE2 have the same device and inode numbers
FILE1 -nt FILE2 FILE1 is newer (modification date) than FILE2
FILE1 -ot FILE2 FILE1 is older than FILE2
-b FILE FILE exists and is block special
-c FILE FILE exists and is character special
-d FILE FILE exists and is a directory
-e FILE FILE exists
-f FILE FILE exists and is a regular file
-g FILE FILE exists and is set-group-ID
-G FILE FILE exists and is owned by the effective group ID
-h FILE FILE exists and is a symbolic link (same as -L)
-k FILE FILE exists and has its sticky bit set
-L FILE FILE exists and is a symbolic link (same as -h)
-O FILE FILE exists and is owned by the effective user ID
-p FILE FILE exists and is a named pipe
-r FILE FILE exists and read permission is granted
-s FILE FILE exists and has a size greater than zero
-S FILE FILE exists and is a socket
-t FD file descriptor FD is opened on a terminal
-u FILE FILE exists and its set-user-ID bit is set
-w FILE FILE exists and write permission is granted
-x FILE FILE exists and execute (or search) permission is granted
Except for -h and -L, all FILE-related tests dereference symbolic links.
Beware that parentheses need to be escaped (e.g., by backslashes) for shells.
INTEGER may also be -l STRING, which evaluates to the length of STRING.
NOTE: [ honors the --help and --version options, but test does not.
test treats each of those as it treats any other nonempty STRING.
NOTE: your shell may have its own version of test and/or [, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
Report [ bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils '[ invocation'
note in particular the part after the Synopses in the following extract from the info file
Code:
File: coreutils.info, Node: test invocation, Next: expr invocation, Prev: true invocation, Up: Conditions
16.3 `test': Check file types and compare values
================================================
`test' returns a status of 0 (true) or 1 (false) depending on the
evaluation of the conditional expression EXPR. Each part of the
expression must be a separate argument.
`test' has file status checks, string operators, and numeric
comparison operators.
`test' has an alternate form that uses opening and closing square
brackets instead a leading `test'. For example, instead of `test -d
/', you can write `[ -d / ]'. The square brackets must be separate
arguments; for example, `[-d /]' does not have the desired effect.
Since `test EXPR' and `[ EXPR ]' have the same meaning, only the former
form is discussed below.
Synopses:
test EXPRESSION
test
[ EXPRESSION ]
[ ]
[ OPTION
Due to shell aliases and built-in `test' functions, using an
unadorned `test' interactively or in a script may get you different
functionality than that described here. Invoke it via `env' (i.e.,
`env test ...') to avoid interference from the shell.
If EXPRESSION is omitted, `test' returns false. If EXPRESSION is a
single argument, `test' returns false if the argument is null and true
otherwise. The argument can be any string, including strings like
`-d', `-1', `--', `--help', and `--version' that most other programs
would treat as options. To get help and version information, invoke
the commands `[ --help' and `[ --version', without the usual closing
brackets. *Note Common options::.
Exit status:
0 if the expression is true,
1 if the expression is false,
2 if an error occurred.
* Menu:
* File type tests:: -[bcdfhLpSt]
* Access permission tests:: -[gkruwxOG]
* File characteristic tests:: -e -s -nt -ot -ef
* String tests:: -z -n = == !=
* Numeric tests:: -eq -ne -lt -le -gt -ge
* Connectives for test:: ! -a -o
|
|
1 members found this post helpful.
|
10-21-2014, 02:02 AM
|
#11
|
Amigo developer
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928
|
No, /bin/[ is not a shell builtin. bash does have both '[' and '[[' as builtins -and they are the ones that usually get used in scripts, unless /bin/[ gets called explicitly with the full path. The same is true for 'test' and /bin/test. And, /bin/[ is not simply a copy of /bin/test -although some systems might have /bin/[ as a link to /bin/test.
If you run '/bin/[ --help' you will not get the same results as '/bin/test' or 'help [' (from the bash command line).
So, in short, '[' & 'test' (from shell) and '/bin/[' & '/bin/test' are four separate things -each with slightly different features. And, of course, the double '[[' is only available as a shell builtin. One other helpful thing is to use the shell built-in 'type' instead of 'which' in order to identify which binary is really being used.
|
|
3 members found this post helpful.
|
All times are GMT -5. The time now is 10:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|