StructureBasic ShellThe shell is very simple (conceptually): it runs in a while loop, repeatedly asking for input to tell it what command to execute. It then executes that command. The loop continues indefinitely, until the user types the built-in command exit, atwhich point it exits. That's it!For reading lines of input, you should use getline(). This allows you to obtain arbitrarily long input lines with ease. Generally, the shell will be run in interactive mode, where the user types a command (one at a time) and the shell acts on it. However, your shell will also support batch mode, in which the shell is given an input file of commands; in this case, the shell should not read user input (from stdin) but rather from this file to get the commands to execute.In either mode, if you hit the end-of-file marker (EOF), you should call exit(0) and exit gracefully.To parse the input line into constituent pieces, you might want to use strsep(). Read the man page (carefully) for more details.To execute commands, look into fork(), exec(), and wait()/waitpid(). See the man pages for these functions, and also read the relevant book chapter for a brief overview.You will note that there are a variety of commands in the exec family; for this project, you must use execv. You should
not use the system() library function call to run a command. Rememberthat if execv() is successful, it will not return; if it does return, there was an error (e.g., the command does not exist). The most challenging part is getting the arguments correctly specified.PathsIn our example above, the user typed ls but the shell knew toexecute the program /bin/ls. How does your shell know this?It turns out that the user must specify a path variable to describe the set of directories to search for executables; the set of directories that comprise the path are sometimes called the search path of the shell. The path variable contains the list of all directories to search, in order, when the user types a command.Important: Note that the shell itself does not implement ls orother commands (except built-ins). All it does is find those executables in one of the directories specified by path and create a new process to run them.To check if a particular file exists in a directory and is executable, consider the access() system call. For example, when the user types ls, and path is set to include both /bin and /usr/bin, try access("/bin/ls", X_OK). If that fails, try "/usr/bin/ls". If that fails too, it is an error.Your initial shell path should contain one directory: `/bin'Note: Most shells allow you to specify a binary specifically without using a search path, using either absolute paths or relative paths. For example, a user could type the absolute
path /bin/ls and execute the ls binary without a search path being needed. A user could also specify a relative path which starts with the current working directory and specifies the executable directly, e.g., ./main. In this project, you do not have to worry about these features.