From owner-freebsd-questions@freebsd.org Thu Oct 26 19:47:10 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 4113DE51D2E for ; Thu, 26 Oct 2017 19:47:10 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay12.qsc.de (mailrelay12.qsc.de [212.99.163.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BF51566F93 for ; Thu, 26 Oct 2017 19:47:08 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay12.qsc.de; Thu, 26 Oct 2017 21:46:23 +0200 Received: from r56.edvax.de (port-92-195-74-193.dynamic.qsc.de [92.195.74.193]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 01DBD3CBF9; Thu, 26 Oct 2017 21:46:21 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id v9QJkKjR002242; Thu, 26 Oct 2017 21:46:21 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Thu, 26 Oct 2017 21:46:20 +0200 From: Polytropon To: Ian Smith Cc: freebsd-questions@freebsd.org, Manish Jain Subject: Re: A request to segregate man pages for shell built-ins Message-Id: <20171026214620.bf8fcbf2.freebsd@edvax.de> In-Reply-To: <20171027021115.A40402@sola.nimnet.asn.au> References: <20171027021115.A40402@sola.nimnet.asn.au> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay12.qsc.de with D63D06A3B77 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1536 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: Thu, 26 Oct 2017 19:47:10 -0000 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: > > > On Wed, 25 Oct 2017 02:23:23 +0000, Manish Jain wrote: > > > [...] > > > (Note : some built-ins (e.g. 'test') do have their own man pages) > > > > Well, test is a binary, a separate program, not a builtin. ;-) > > > > % 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. > Fortunately - or it'd be much slower with, um, testing. So which isn't > aware of the sh(1) builtin (since sh(1) has no 'which' builtin, so uses > which(1)) .. whereas csh(1) has builtin which but no 'test' (as such, > though all test's, um, tests can be done in csh). Easily confusing, eh? > > 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 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? Oh, and nobody with a sane mind writes shell scripts in C Shell. Of course I've done it. ;-) > > Of course, [ and test are actually one and the same binary. > > And the builtin test in sh(1) is correctly covered by test(1). Yes, sh implements it as per the manpage. > > Keep in mind some shells also offer a builtin replacement for > > an existing binary. A good example is echo where a binary exists, > > but the C Shell has its own internal echo, while BASH uses the > > binary one: > > > > % 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. > > In such a case, what should "man echo" show? > > Among other things, see builtin(1)" .. oh, it already does. > > 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... ;-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...