Re: A file named "["?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jun 05, 2012 at 10:17:47PM +0200, Michael Schwendt wrote:
On Tue, 05 Jun 2012 12:35:34 -0700, jdow wrote:

On 2012/06/05 11:55, Michael Schwendt wrote:
> On Tue, 5 Jun 2012 14:40:23 -0400, Alex wrote:
>
>> It's used in shell scripts, such as an "if" statement, such as "if [
>> $? -eq 0 ]". Bash actually runs that command.
>
> Not Bash.
>
> $ type [
> [ is a shell builtin
>
> Also see "man [".
>

$ type /usr/bin/[
/usr/bin/[ is /usr/bin/[

Of course. What are you trying to prove?

Bash doesn't run that command. "man test" explains it, too:

| NOTE: your shell may have its own version of test and/or [, which  usu‐
| ally  supersedes  the  version  described  here.   Please refer to your
| shell's documentation for details about the options it supports.

--
Fedora release 17 (Beefy Miracle) - Linux 3.3.7-1.fc17.x86_64
loadavg: 1.78 1.58 1.44
--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org

	### End of Message from Michael Schwendt ###

I hope this puts the issue to bed:

An unadorned '[' in bash (or borne sh, or zsh, and probably others) actually is a built-in command. This speed tests tremendously by preventing execing every time a test needs to be performed.

For some ancient shells test (a.k.a. '/usr/bin/[') was an external command. It is still provided for backwards compatibility.

In bash you *can* use it, so long as you either call it long-hand:
 $ /usr/bin/\[ -n "$var" ]
But it would be stupid to do so.

Every once in a while, you might encounter a program that execs your commands directly, i.e. *not* in a shell. IIRC, Udev RUN= and PROGRAM== are examples of these. If you want to test something, then you would have to use something like:

  PROGRAM=="bash -c '[ "$a" -eq "$b" ]'

This is clumsy*. Because you have /usr/bin/\[ in the path, you could probably get away with:

  PROGRAM=='[ "$a" -eq "$b" ]'

* ok, it's not completely fair to call this clumsy, because when you run bash, you also get all your functions, aliases and other built-ins, so oftentimes it actually *is* better to use 'bash -c'.

HTH

--
×-×-×-×-×-×-×-×-×-×-×
  Jeffrey A. Gipson
×-×-×-×-×-×-×-×-×-×-×

Attachment: smime.p7s
Description: S/MIME cryptographic signature

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux