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):

# $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

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.

  • It would be uncommon to actually use these external utilities as the builtins would be used first. It also looks like it could have unwanted consequences. For example, a script may use the external cd as a way of testing whether changing working directory would work, and then rely on the fact that an external cd would actually not change directory... – Kusalananda Apr 1 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.