Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Oct 2017 03:57:42 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Ian Smith <smithi@nimnet.asn.au>
Cc:        Carl Johnson <carlj@peak.org>, freebsd-questions@freebsd.org
Subject:   Re: A request to segregate man pages for shell built-ins
Message-ID:  <20171028035742.8a0e909d.freebsd@edvax.de>
In-Reply-To: <20171027232555.W40402@sola.nimnet.asn.au>
References:  <mailman.113.1509019202.90583.freebsd-questions@freebsd.org> <20171027021115.A40402@sola.nimnet.asn.au> <20171026214620.bf8fcbf2.freebsd@edvax.de> <20171027232555.W40402@sola.nimnet.asn.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 27 Oct 2017 23:56:15 +1100 (EST), Ian Smith wrote:
> 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 <freebsd@edvax.de> wrote:
> [...]
>  > 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'

Yes, rediretion is a problem, and there are more (if - then -
endif, foreach, set, probably quoting issues, etc.). The C shell
simply isn't that great for scripting. But under certain
curcumstances and preferences, its dialog behaviour is more
convenient than that of bash in its stock configuration.

There is a nice article about it: "Csh Programming Considered
Harmful", to be found here:

https://www-uxsup.csx.cam.ac.uk/misc/csh.html

I would definitely _not_ write a script again for the C shell,
but the one (!) I wrote still works, so I don't think it
should be rewritten - "nyet kaputnik, nyet reparaturowka". ;-)



>  > >  > 	% 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 ..

That's a really interesting experiment.



>  > > 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?

In worst case, the C shell might not be available. I actually have
no idea how bad it must be, but it's possible that everything you
have is the "dumb" /bin/sh, and you need to deal with that. You
_never_ know what strange symptoms a damaged system could expose.
So dealing with "all I have is this stupid shell" is one of the
skills a good system administrator should have. :-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171028035742.8a0e909d.freebsd>