* [gentoo-user] "/usr/bin/[" and coreutils
@ 2011-10-12 5:35 William Kenworthy
2011-10-12 5:42 ` Canek Peláez Valdés
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: William Kenworthy @ 2011-10-12 5:35 UTC (permalink / raw
To: Gentoo Users
I have been checking my system for some deep seated problems and in the
process, ran across the fact that "equery files sys-apps/coreutils-8.7"
shows a file included called "/usr/bin/[" - thats right, left square
bracket!
Is that a bug or if real, what would you use it for? It doesnt seem to
be on the file system ...
moriah ~ # /usr/bin/[
/usr/bin/[: missing `]'
moriah ~ #
doesnt show much!
BillK
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-12 5:35 [gentoo-user] "/usr/bin/[" and coreutils William Kenworthy
@ 2011-10-12 5:42 ` Canek Peláez Valdés
2011-10-12 16:49 ` Jonas de Buhr
2011-10-12 5:42 ` Manuel McLure
2011-10-12 5:45 ` meino.cramer
2 siblings, 1 reply; 13+ messages in thread
From: Canek Peláez Valdés @ 2011-10-12 5:42 UTC (permalink / raw
To: gentoo-user
On Tue, Oct 11, 2011 at 10:35 PM, William Kenworthy <billk@iinet.net.au> wrote:
> I have been checking my system for some deep seated problems and in the
> process, ran across the fact that "equery files sys-apps/coreutils-8.7"
> shows a file included called "/usr/bin/[" - thats right, left square
> bracket!
>
> Is that a bug or if real, what would you use it for? It doesnt seem to
> be on the file system ...
>
> moriah ~ # /usr/bin/[
> /usr/bin/[: missing `]'
> moriah ~ #
>
> doesnt show much!
Relax. It's an alias for "test", so instead of using
if test blah; then
...
fi
in bash, you can use
if [ blah ]; then
...
fi
Just do /usr/bin/[ --help to get an idea. It has been there since I
started using Linux, if I remember correctly, many years ago.
Regards.
--
Canek Peláez Valdés
Posgrado en Ciencia e Ingeniería de la Computación
Universidad Nacional Autónoma de México
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-12 5:35 [gentoo-user] "/usr/bin/[" and coreutils William Kenworthy
2011-10-12 5:42 ` Canek Peláez Valdés
@ 2011-10-12 5:42 ` Manuel McLure
2011-10-12 5:45 ` meino.cramer
2 siblings, 0 replies; 13+ messages in thread
From: Manuel McLure @ 2011-10-12 5:42 UTC (permalink / raw
To: gentoo-user
On Tue, Oct 11, 2011 at 10:35 PM, William Kenworthy <billk@iinet.net.au> wrote:
> I have been checking my system for some deep seated problems and in the
> process, ran across the fact that "equery files sys-apps/coreutils-8.7"
> shows a file included called "/usr/bin/[" - thats right, left square
> bracket!
>
> Is that a bug or if real, what would you use it for? It doesnt seem to
> be on the file system ...
>
> moriah ~ # /usr/bin/[
> /usr/bin/[: missing `]'
> moriah ~ #
>
> doesnt show much!
'/usr/bin/[' is a synonym for the '/usr/bin/test' utility. It's used
in shell scripts like
if [ -f /etc/passwd ] ; then
...
So don't worry. It's supposed to be there.
--
Manuel A. McLure WW1FA <manuel@mclure.org> <http://www.mclure.org>
...for in Ulthar, according to an ancient and significant law,
no man may kill a cat. -- H.P. Lovecraft
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-12 5:35 [gentoo-user] "/usr/bin/[" and coreutils William Kenworthy
2011-10-12 5:42 ` Canek Peláez Valdés
2011-10-12 5:42 ` Manuel McLure
@ 2011-10-12 5:45 ` meino.cramer
2011-10-12 6:04 ` William Kenworthy
2 siblings, 1 reply; 13+ messages in thread
From: meino.cramer @ 2011-10-12 5:45 UTC (permalink / raw
To: gentoo-user
William Kenworthy <billk@iinet.net.au> [11-10-12 07:40]:
> I have been checking my system for some deep seated problems and in the
> process, ran across the fact that "equery files sys-apps/coreutils-8.7"
> shows a file included called "/usr/bin/[" - thats right, left square
> bracket!
>
> Is that a bug or if real, what would you use it for? It doesnt seem to
> be on the file system ...
>
> moriah ~ # /usr/bin/[
> /usr/bin/[: missing `]'
> moriah ~ #
>
> doesnt show much!
>
> BillK
>
>
Hi Wiiliam,
this is a convenient 'abbreviation' or 'alias' for cobnstructs such this one
if [ foo ]
then
bar
fi
in shell scripting.
Most shells have implemented this as a builtin (and 'test' also)
though.
HTH!
Best regards,
mcc
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-12 5:45 ` meino.cramer
@ 2011-10-12 6:04 ` William Kenworthy
0 siblings, 0 replies; 13+ messages in thread
From: William Kenworthy @ 2011-10-12 6:04 UTC (permalink / raw
To: gentoo-user
On Wed, 2011-10-12 at 07:45 +0200, meino.cramer@gmx.de wrote:
> William Kenworthy <billk@iinet.net.au> [11-10-12 07:40]:
> > I have been checking my system for some deep seated problems and in the
> > process, ran across the fact that "equery files sys-apps/coreutils-8.7"
> > shows a file included called "/usr/bin/[" - thats right, left square
> > bracket!
> >
> > Is that a bug or if real, what would you use it for? It doesnt seem to
> > be on the file system ...
> >
> > moriah ~ # /usr/bin/[
> > /usr/bin/[: missing `]'
> > moriah ~ #
> >
> > doesnt show much!
> >
> > BillK
> >
> >
>
> Hi Wiiliam,
>
> this is a convenient 'abbreviation' or 'alias' for cobnstructs such this one
>
> if [ foo ]
> then
> bar
> fi
>
> in shell scripting.
>
> Most shells have implemented this as a builtin (and 'test' also)
> though.
>
> HTH!
>
> Best regards,
> mcc
>
>
GAH! - now I remember ... goes back to my basic unix skills (or lack
of :) - must be getting old ...
Thanks all.
BillK
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-12 5:42 ` Canek Peláez Valdés
@ 2011-10-12 16:49 ` Jonas de Buhr
2011-10-13 13:38 ` Jesús J. Guerrero Botella
0 siblings, 1 reply; 13+ messages in thread
From: Jonas de Buhr @ 2011-10-12 16:49 UTC (permalink / raw
To: gentoo-user
Am Tue, 11 Oct 2011 22:42:00 -0700
schrieb Canek Peláez Valdés <caneko@gmail.com>:
> On Tue, Oct 11, 2011 at 10:35 PM, William Kenworthy
> <billk@iinet.net.au> wrote:
> > I have been checking my system for some deep seated problems and in
> > the process, ran across the fact that "equery files
> > sys-apps/coreutils-8.7" shows a file included called "/usr/bin/[" -
> > thats right, left square bracket!
> >
> > Is that a bug or if real, what would you use it for? It doesnt
> > seem to be on the file system ...
> >
> > moriah ~ # /usr/bin/[
> > /usr/bin/[: missing `]'
> > moriah ~ #
> >
> > doesnt show much!
>
> Relax. It's an alias for "test"
technically it's not an alias, but different binaries
% ls -l /usr/bin/\[
-rwxr-xr-x 1 root root 35096 Jan 20 2011 /usr/bin/[
% ls -l /usr/bin/test
-rwxr-xr-x 1 root root 31000 Jan 20 2011 /usr/bin/test
built from the same source file coreutils/src/test.c with a
#define LBRACKET
that mainly changes the behavior of the argument parser in case it is
built as [.
>, so instead of using
>
> if test blah; then
> ...
> fi
>
> in bash, you can use
>
> if [ blah ]; then
> ...
> fi
>
> Just do /usr/bin/[ --help to get an idea. It has been there since I
> started using Linux, if I remember correctly, many years ago.
>
> Regards.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-12 16:49 ` Jonas de Buhr
@ 2011-10-13 13:38 ` Jesús J. Guerrero Botella
2011-10-13 13:50 ` Alan McKinnon
0 siblings, 1 reply; 13+ messages in thread
From: Jesús J. Guerrero Botella @ 2011-10-13 13:38 UTC (permalink / raw
To: gentoo-user
Yes, it's a different binary, and it's perfectly usual to find it in a
Linux system.
But note that, at least in bash, you rarely will be using /usr/bin/[
unless you reference it using the full path (either in a relative or
absolute way). This is because bash has a builtin that takes over that
binary file. You can check that (or any other command) by using the
"type" instruction (again, this is for bash).
# LC_ALL=C type [
[ is a shell builtin
The same goes for 'test'.
Those binaries are probably there just in case that some init or
system script written for a standard bourne shell (like the busybox
one) needs it. But don't take my word for it. I am not sure right now.
--
Jesús Guerrero Botella
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-13 13:38 ` Jesús J. Guerrero Botella
@ 2011-10-13 13:50 ` Alan McKinnon
2011-10-13 13:59 ` Michael Mol
0 siblings, 1 reply; 13+ messages in thread
From: Alan McKinnon @ 2011-10-13 13:50 UTC (permalink / raw
To: gentoo-user
On Thu, 13 Oct 2011 15:38:08 +0200
Jesús J. Guerrero Botella <jesus.guerrero.botella@gmail.com> wrote:
> Yes, it's a different binary, and it's perfectly usual to find it in a
> Linux system.
>
> But note that, at least in bash, you rarely will be using /usr/bin/[
> unless you reference it using the full path (either in a relative or
> absolute way). This is because bash has a builtin that takes over that
> binary file. You can check that (or any other command) by using the
> "type" instruction (again, this is for bash).
>
> # LC_ALL=C type [
> [ is a shell builtin
>
> The same goes for 'test'.
>
> Those binaries are probably there just in case that some init or
> system script written for a standard bourne shell (like the busybox
> one) needs it. But don't take my word for it. I am not sure right now.
You might not be sure, but that doesn't stop you still being correct :-)
The binaries are usually POSIX-compliant, whereas the builtins may
include extra bashisms (which tend to break apps expecting just
the basic POSIX behaviour)
--
Alan McKinnnon
alan.mckinnon@gmail.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-13 13:50 ` Alan McKinnon
@ 2011-10-13 13:59 ` Michael Mol
2011-10-13 14:30 ` Alan McKinnon
0 siblings, 1 reply; 13+ messages in thread
From: Michael Mol @ 2011-10-13 13:59 UTC (permalink / raw
To: gentoo-user
On Thu, Oct 13, 2011 at 9:50 AM, Alan McKinnon <alan.mckinnon@gmail.com> wrote:
> On Thu, 13 Oct 2011 15:38:08 +0200
> Jesús J. Guerrero Botella <jesus.guerrero.botella@gmail.com> wrote:
>
>> Yes, it's a different binary, and it's perfectly usual to find it in a
>> Linux system.
>>
>> But note that, at least in bash, you rarely will be using /usr/bin/[
>> unless you reference it using the full path (either in a relative or
>> absolute way). This is because bash has a builtin that takes over that
>> binary file. You can check that (or any other command) by using the
>> "type" instruction (again, this is for bash).
>>
>> # LC_ALL=C type [
>> [ is a shell builtin
>>
>> The same goes for 'test'.
>>
>> Those binaries are probably there just in case that some init or
>> system script written for a standard bourne shell (like the busybox
>> one) needs it. But don't take my word for it. I am not sure right now.
>
> You might not be sure, but that doesn't stop you still being correct :-)
>
> The binaries are usually POSIX-compliant, whereas the builtins may
> include extra bashisms (which tend to break apps expecting just
> the basic POSIX behaviour)
I haven't encountered POSIX-dependent apps breaking on bash, but I
have encountered the reverse. My most annoying experience was when I
tried building cinelerra on Debian a few years back. Cinelerra's
script started with #!/bin/sh, but depended on bashisms--and I was
running dash.
--
:wq
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-13 13:59 ` Michael Mol
@ 2011-10-13 14:30 ` Alan McKinnon
2011-11-08 1:53 ` Claudio Roberto França Pereira
0 siblings, 1 reply; 13+ messages in thread
From: Alan McKinnon @ 2011-10-13 14:30 UTC (permalink / raw
To: gentoo-user
On Thu, 13 Oct 2011 09:59:21 -0400
Michael Mol <mikemol@gmail.com> wrote:
> > The binaries are usually POSIX-compliant, whereas the builtins may
> > include extra bashisms (which tend to break apps expecting just
> > the basic POSIX behaviour)
>
> I haven't encountered POSIX-dependent apps breaking on bash, but I
> have encountered the reverse. My most annoying experience was when I
> tried building cinelerra on Debian a few years back. Cinelerra's
> script started with #!/bin/sh, but depended on bashisms--and I was
> running dash.
So you've also run into clueless devs and maintainers who know
almost nothing about shells?
Your example is an extreme one :-), but it's common enough to find
bashisms in scripts with an sh shebang
--
Alan McKinnnon
alan.mckinnon@gmail.com
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-10-13 14:30 ` Alan McKinnon
@ 2011-11-08 1:53 ` Claudio Roberto França Pereira
2011-11-08 6:01 ` Pandu Poluan
0 siblings, 1 reply; 13+ messages in thread
From: Claudio Roberto França Pereira @ 2011-11-08 1:53 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 93 bytes --]
What about [[? I've seen scripts using [[ instead of only one [. Whats the
point/difference?
[-- Attachment #2: Type: text/html, Size: 101 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-11-08 1:53 ` Claudio Roberto França Pereira
@ 2011-11-08 6:01 ` Pandu Poluan
2011-11-08 6:03 ` Pandu Poluan
0 siblings, 1 reply; 13+ messages in thread
From: Pandu Poluan @ 2011-11-08 6:01 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 647 bytes --]
On Nov 8, 2011 9:02 AM, "Claudio Roberto França Pereira" <spideybr@gmail.com>
wrote:
>
> What about [[? I've seen scripts using [[ instead of only one [. Whats
the point/difference?
AFAIK [[ was originally a bash-specific built-in command that provides more
functionality than /bin/[, but can still use /bin/['s convoluted syntax.
The two converged quickly, though. IIRC [ is now also a bash built-in,
which still maintains compatibility with /bin/[
An example:
[ $VAR ] will produce an error if VAR is empty or unset, but [[ $VAR ]]
won't.
(for the former, you have to put double quotes around, e.g., [ "$VAR"] )
Rgds,
[-- Attachment #2: Type: text/html, Size: 783 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [gentoo-user] "/usr/bin/[" and coreutils
2011-11-08 6:01 ` Pandu Poluan
@ 2011-11-08 6:03 ` Pandu Poluan
0 siblings, 0 replies; 13+ messages in thread
From: Pandu Poluan @ 2011-11-08 6:03 UTC (permalink / raw
To: gentoo-user
[-- Attachment #1: Type: text/plain, Size: 847 bytes --]
On Nov 8, 2011 1:01 PM, "Pandu Poluan" <pandu@poluan.info> wrote:
>
>
> On Nov 8, 2011 9:02 AM, "Claudio Roberto França Pereira" <
spideybr@gmail.com> wrote:
> >
> > What about [[? I've seen scripts using [[ instead of only one [. Whats
the point/difference?
>
> AFAIK [[ was originally a bash-specific built-in command that provides
more functionality than /bin/[, but can still use /bin/['s convoluted
syntax.
>
> The two converged quickly, though. IIRC [ is now also a bash built-in,
which still maintains compatibility with /bin/[
>
> An example:
>
> [ $VAR ] will produce an error if VAR is empty or unset, but [[ $VAR ]]
won't.
>
> (for the former, you have to put double quotes around, e.g., [ "$VAR"] )
>
Uh... of course there should be a space between the second double-quote and
the closing bracket.
Rgds,
[-- Attachment #2: Type: text/html, Size: 1119 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2011-11-08 6:04 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-12 5:35 [gentoo-user] "/usr/bin/[" and coreutils William Kenworthy
2011-10-12 5:42 ` Canek Peláez Valdés
2011-10-12 16:49 ` Jonas de Buhr
2011-10-13 13:38 ` Jesús J. Guerrero Botella
2011-10-13 13:50 ` Alan McKinnon
2011-10-13 13:59 ` Michael Mol
2011-10-13 14:30 ` Alan McKinnon
2011-11-08 1:53 ` Claudio Roberto França Pereira
2011-11-08 6:01 ` Pandu Poluan
2011-11-08 6:03 ` Pandu Poluan
2011-10-12 5:42 ` Manuel McLure
2011-10-12 5:45 ` meino.cramer
2011-10-12 6:04 ` William Kenworthy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox