From owner-freebsd-questions@freebsd.org Fri Oct 27 12:56:32 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EF3C6E44866 for ; Fri, 27 Oct 2017 12:56:32 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 63B3564A50 for ; Fri, 27 Oct 2017 12:56:31 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id v9RCuFip096396; Fri, 27 Oct 2017 23:56:16 +1100 (EST) (envelope-from smithi@nimnet.asn.au) Date: Fri, 27 Oct 2017 23:56:15 +1100 (EST) From: Ian Smith To: Polytropon cc: freebsd-questions@freebsd.org, Manish Jain , Carl Johnson Subject: Re: A request to segregate man pages for shell built-ins In-Reply-To: <20171026214620.bf8fcbf2.freebsd@edvax.de> Message-ID: <20171027232555.W40402@sola.nimnet.asn.au> References: <20171027021115.A40402@sola.nimnet.asn.au> <20171026214620.bf8fcbf2.freebsd@edvax.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Oct 2017 12:56:33 -0000 On Thu, 26 Oct 2017 21:46:20 +0200, Polytropon wrote: > On Fri, 27 Oct 2017 03:02:17 +1100 (EST), Ian Smith wrote: > > In freebsd-questions Digest, Vol 699, Issue 4, Message: 3 > > On Wed, 25 Oct 2017 15:16:47 +0200 Polytropon wrote: > > > % which test > > > /bin/test > > > > > > % which [ > > > /bin/[ > > > > % which test > > /bin/test > > % sh > > $ which test > > /bin/test > > > > These results are correct for test, but it _is_ builtin to sh(1): > > > > [ A built-in equivalent of test(1). > > test A built-in equivalent of test(1). > > Yes, this is true as long as the script uses [ or test. Some do > explicitely call /bin/test. I'm almost sure this isn't true anymore > on today's modern FreeBSD, but older UNIX scripts occassionally > were constructed in such a way that they called the binaries > explicitely with the full path. Maybe this has been some portability > issue. Wwll you could do that .. but I'd expect it to be slower (untested). > > Command External csh(1) sh(1) > > echo Yes Yes Yes > > test Yes No Yes > > To complete that table: > > Command External csh(1) sh(1) > which Yes Yes No Indeed, after posting I thought I should have added that :) > So the result of the command is a bit confusing as "which", no > matter if being internal or external, is showing the binary as > a result whereas it should show builtin. Maybe this is another > "fight" between external and builtin? But see below .. > Oh, and nobody with a sane mind writes shell scripts in C Shell. > Of course I've done it. ;-) Agreed, but I guess I'm not quite so insane :) For one thing, I find csh's redirections confusing and less complete, so even interactively I'll do things to avoid csh syntax like (as a wild example): % sh -c 'for i in a b c; do echo $i; sleep 2; done 2>&1 >file' > > > % which echo > > > echo: shell built-in command. > > > > > > $ which echo > > > /bin/echo > > > > Again, despite that, echo _is_ builtin to sh(1) - and has more options. > > That is correct (even though sh's "which echo" reports the binary); > sh's echo supports escape sequences using the -e option, while the > binary doesn't. However, as Carl Johnson since posted: > 'Which' is an external for sh so it can't show builtin commands. Sh has > the builtin 'type' command which is the equivalent of 'which' for csh. which was news to me. So I tried something: % sh $ alias $ type type type is a shell builtin $ type which which is a tracked alias for /usr/bin/which $ $ alias which=type $ which which which is an alias for type $ type which which is an alias for type $ which test test is a shell builtin $ which echo echo is a shell builtin $ $ unalias which $ which which /usr/bin/which $ which echo /bin/echo $ which test /bin/test So thanks for that, Carl .. > > Perhaps sh(1) could use a smarter 'which' that exposes its own builtins > > such as these two more readily - but who dares mess with sh(1) ? :) > > Interactively? Probably only the poor souls dropped into > maintenance mode (single user mode) without the ability to > start a more comfortable interactive shell... ;-) Ability? Just choose '/bin/csh' on entry, or type 'csh' once in SUM? cheers, Ian