3

I am trying to write a tiny shell. How can I distinguish that if an input argument is a builtin command (if so, I will fork and execute it)?
PS. I am working on Ubuntu 18.04 LTS.

TianpingHsu
  • 91
  • 2
  • 5
  • Possible duplicate of [How to check if command exists in a shell script?](https://stackoverflow.com/questions/7522712/how-to-check-if-command-exists-in-a-shell-script) – kiran Biradar Aug 06 '18 at 08:28
  • 4
    You're writing a shell, _you_ decide what utilities to implement as builtins (except for the few that are _required_ to be builtins, check the POSIX standard). – Kusalananda Aug 06 '18 at 08:44

1 Answers1

3

Well, if you are writing your own shell, then technically it is up to your implementation what is and isn't a built in command.

For builtins

In bash, ksh etc. you can use compgen -b to generate a list of builtins in corresponding shell.

-A action

...

builtin

Names of shell builtin commands. May also be specified as -b.

For non builtins

For non-builtins search the path, or refer to FHS and search e.g. /bin /sbin /usr/bin /usr/sbin.

visibleman
  • 3,175
  • 1
  • 14
  • 27