Reputation: 71
For some reasons, I want my program to use external functions instead of built-in shell functions (e.g. echo
). The program has a call to system()
which use /bin/sh
to execute the argument.
With bash
shell I already know that enable -n <fnc>
can prevent the shell to use the built-in function. However, I couldn't find a similar way for sh
shell.
Is it possible to do this for sh
?
Upvotes: 3
Views: 476
Reputation: 860
It was answered in a related question:
Prepend the command with env
.
$ env echo "Hello"
env
is a standalone program, which doesn't have access to the shell builtins, such as echo
, so it will search for echo
in the command path.
Upvotes: 1
Reputation: 123460
To force any shell to use an external executable instead of a builtin command, simply specify it by path:
# Use whatever the shell defaults to
echo "Hello World"
# Always use the specified external binary
/bin/echo "Hello World"
This behavior is specified in POSIX 2.9.1:
If the command name contains at least one slash, the shell shall execute the utility in a separate utility environment with actions equivalent to calling the execl() function
Upvotes: 1