What happens when you type ls -l in the shell

Program Specifications

Basic Shell

Built-in Commands

[optionalSpace]exit[optionalSpace]
[optionalSpace]pwd[optionalSpace]
[optionalSpace]cd[optionalSpace]
[optionalSpace]cd[oneOrMoreSpace]dir[optionalSpace]
[optionalSpace]wait[optionalSpace]
% cd
% pwd
/afs/cs.wisc.edu/u/m/j/username
% echo $PWD
/u/m/j/username
% ./mysh
mysh> pwd
/afs/cs.wisc.edu/u/m/j/username

Redirection

ls > out1 out2
ls > out1 out2 out3
ls > out1 > out2

Background Jobs

mysh> ls &
mysh> ls &
mysh> ps &
mysh> find . -name *.c -print &
mysh> ls &
mysh> ps &
mysh> find . -name *.c -print &
mysh> wait

Fun Feature

prompt> hello.py

Program Errors

char error_message[30] = "An error has occurred\n";
write(STDERR_FILENO, error_message, strlen(error_message));

White Spaces

mysh> ls
mysh> ls > a
mysh> ls>a

Batch Mode

write(STDOUT_FILENO, cmdline, strlen(cmdline));
emperor1% ./mysh
mysh> ls
some output printed here
mysh> ls > /tmp/ls-out
some output printed here
mysh> notACommand
some error printed here
ls
ls > /tmp/ls-out
notACommand
prompt> ./mysh myBatchFile
ls
some output printed here
ls > /tmp/ls-out
some output printed here
notACommand
some error printed here

Defensive Programming and Error Messages

char error_message[30] = "An error has occurred\n";
write(STDERR_FILENO, error_message, strlen(error_message));
  • An incorrect number of command line arguments to your shell program.
  • A command does not exist or cannot be executed.
  • A very long command line (over 512 characters, excluding the carriage return)
  • An empty command line.
  • Multiple white spaces on a command line.

Hints

Basic Shell

Built-in Commands

Redirection

Miscellaneous Hints

Handin

emperor1% ./mysh
emperor1% ./mysh inputTestFile

Grading

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store