How little work could `/usr/bin/cd` or `/usr/bin/wait` do and still be conforming?
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.
command posix
add a comment |
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.
command posix
add a comment |
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.
command posix
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.
command posix
command posix
edited 1 hour ago
Gregory Nisbet
asked 1 hour ago
Gregory NisbetGregory Nisbet
1,4541020
1,4541020
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507614%2fhow-little-work-could-usr-bin-cd-or-usr-bin-wait-do-and-still-be-conformin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507614%2fhow-little-work-could-usr-bin-cd-or-usr-bin-wait-do-and-still-be-conformin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown