I'm trying to create a basic shell, but I have a problem.
The shell changes directory just fine, and outputs an error if the user inputs an invalid directory. The shell also has an internal command for "pwd" and prints out the new working directory after changing directory. However, if I call the "ls" command after changing the directory, I get the following error :
"ls: cannot access : No such file or directory".
The "cd" command is handled in the parent process and the working directory is changed successfully. execvp() is called in the child process. If I call the "ls" command with the new working directory, the ls command lists out the files just fine, but if I just call "ls" by itself I get the error. What could be the cause of the problem?
Copyright Notice:Content Author:「user5944648」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35476143/basic-shell-ls-command-after-chdir