D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

[LUG]Re: trivial shell script - reinvented 16 years later

 

On Thursday, 19 October 2023 05:11:46 BST rds_met wrote:
> 
> "mytrue.sh":
> #!/bin/sh
> exit 0

Also (at least in bash):

simon@rodney:/tmp$ file mytrue
mytrue: empty

simon@rodney:/tmp$ ./mytrue && echo true
true

Is that the same?

> "myfalse.sh":
> #!/bin/sh
> exit 1

:)

"true" and "false" are usually shell builtin commands to avoid the cost of 
spawning a process.

simon@rodney:/tmp$ type false
false is a shell builtin
simon@rodney:/tmp$ type true
true is a shell builtin

"/bin/false" is used for certain types of accounts where you don't want that 
user to be able to spawn a shell (see /etc/passwd).

Also we now have "/usr/sbin/nologin" to be the default shell which prints a 
nice message before failing, somehow "nologin" is smaller than "false" on my 
system (presumably no "--version" and "--help" options).

simon@rodney:/usr/sbin$ /usr/sbin/nologin
This account is currently not available.

 I vaguely recall Unicos had one of the text manipulation commands (I think 
"basename") was implemented using totally over the top shell script using 
"expr". Be interesting to see the space/performance trade off one could make by 
replacing executables like this.

These days I have 4261 commands in /usr/bin, heck I have 121 with "llvm" in 
the command, and I'm pretty sure I only installed that to try something out 
with a different compiler the one time, so no way anyone is learning all of 
those. 

I have 77 different commands for manipulating Portable Any Maps, that project 
is about the same age as Linux, and despite having used them to automate image 
manipulation many years ago I've only used a handful of them in anger.



-- 
The Mailing List for the Devon & Cornwall LUG
FAQ: https://www.dcglug.org.uk/faq/