Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11317

Re: Worth mentioning in documentation

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!usenet.stanford.edu!not-for-mail
From Bob Proulx <bob@proulx.com>
Newsgroups gnu.bash.bug
Subject Re: Worth mentioning in documentation
Date Mon, 10 Aug 2015 14:02:34 -0600
Lines 49
Approved bug-bash@gnu.org
Message-ID <mailman.8092.1439236966.904.bug-bash@gnu.org> (permalink)
References <3156909.AJj7susDjE@debxuan> <2473887.nPWqTkAiyd@debxuan> <20150807122454.GU4309@eeg.ccf.org> <3273328.haPDicsXFC@debxuan> <20150810121925.GV4309@eeg.ccf.org>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1439236967 22573 208.118.235.17 (10 Aug 2015 20:02:47 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org, Juanma <juan-manuel.menendez@tecsidel.es>
Envelope-to bug-bash@gnu.org
Mail-Followup-To bug-bash@gnu.org, Juanma <juan-manuel.menendez@tecsidel.es>
Content-Disposition inline
In-Reply-To <20150810121925.GV4309@eeg.ccf.org>
User-Agent Mutt/1.5.23 (2014-03-12)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 3.x
X-Received-From 216.17.153.58
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.14
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:11317

Show key headers only | View raw


Greg Wooledge wrote:
> Juanma wrote:
> > > [ is an ordinary command (a "shell builtin")
> > 
> > Here is another point I find confusing: I thought a "shell builtin" didn't
> > have a separate binary executable file, like 'cd' (which cd => fail), but
> > some of them do have such form (which [ => /usr/bin/[ ; which pwd =>
> > /bin/pwd). I also fail to see how 'test' modifies the state of the shell
> > itself (like 'cd' does), or why it is "impossible or inconvenient to obtain
> > [its functionality] with separate utilities".
> 
> Don't use which(1).  Which is an external program, so it has no knowledge
> of the shell's builtins, aliases, functions and keywords.  Instead, use
> type.

Another problem with 'which' is that it was originally designed and
written for csh users specifically.  It was a csh script and would
source the users ~/.cshrc file so as to acquire their aliases from
there so as to be able to report user aliases.  I think it is still
that way on HP-UX (and probably others) for example.

However that obviously won't work well for bash, ksh, zsh, and other
shell users.  And IMNHO csh is a terrible shell regardless of the tcsh
users using it who think otherwise.  Therefore some distributions such
as Debian have rewritten 'which' as a /bin/sh script meaning that
'which' behaves differently on different systems.  It is non-portable.

> imadev:~$ type cd
> cd is a shell builtin
> imadev:~$ type [[
> [[ is a shell keyword
> imadev:~$ type -a test
> test is a shell builtin
> test is /usr/bin/test
> test is /bin/test
> 
> Bash implements test as a builtin not because it's necessary, but simply
> for efficiency.  Forking a whole process to test whether two strings are
> equal would be horribly wasteful.

An important mental concept is that test and [ must *behave* the same
as if they were an external program.  They are internal builtins for
efficiency now but everything behaves the same if they are external
programs.  This is why quoting as if they were external programs is
required.  On the other hand [[ has always been a builtin and
therefore the shell can avoid one layer of quoting and does.

Bob

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Worth mentioning in documentation Bob Proulx <bob@proulx.com> - 2015-08-10 14:02 -0600

csiph-web