Can the executables with the same names as shell builtins get away with doing a lot less "work" than the shell builtins do? For instance, could the fg
executable just exit abnormally immediately? Could the wait
and jobs
executable exit 0
if given no arguments and exit 1
otherwise?
So, on OS X, for instance, /usr/bin/cd
and /usr/bin/wait
are the following script(s):
#!/bin/sh
# $FreeBSD: src/usr.bin/alias/generic.sh,v 1.2 2005/10/24 22:32:19 cperciva Exp $
# This file is in the public domain.
builtin `echo ${0##*/} | tr \[:upper:] \[:lower:]` ${1+"$@"}
This will really attempt to call the sh
builtin with the same name as the file the script resides at, the same is true for a bunch of other utilities:
% grep -rl 'alias/generic[.]sh' /usr/bin
/usr/bin/umask
/usr/bin/unalias
/usr/bin/alias
/usr/bin/wait
/usr/bin/hash
/usr/bin/fc
/usr/bin/read
/usr/bin/type
/usr/bin/getopts
/usr/bin/bg
/usr/bin/fg
/usr/bin/cd
/usr/bin/command
/usr/bin/jobs
/usr/bin/ulimit
Based on this question about the usefulness of an external cd
command and one of its answers and this question about printf
in yash
, I think I understand the rationale for the existence of these commands in the first place, I'm just wondering if a select few of them could do less work than they currently do.
cd
as a way of testing whether changing working directory would work, and then rely on the fact that an externalcd
would actually not change directory... – Kusalananda Apr 01 '19 at 08:00