The Shell
- The shell is a special purpose program designed to read commands typed by the user and execute appropriate programs in response to those commands
- Sometimes called a command interpreter
- It is the thing you type to much of the time. (Not the editor)
- Wikipedia says that a shell is either command line or gui
- Unix/LINUX is different from other os where in linux the shell is independent of the kernel.
- In fact, there are multiple shells
- Bourne Shell (/bin/sh) (perhaps)
- c shell (csh)
- korn shell (ksh)
- Bourne again shell (bash)
- Things shells do (via bash.
- globbing - filename expansion
- You know about this
- The use of wildcards similar to regular expressions
- *: matches anything,
- sort of.
- does not match things starting with a .
- ?: matches a single character
- [...]:
- matches any one enclosed character.
- [abc] matches the files a, b or c
- [abc]* matches any file beginning with a,b, or c
- [a-f] is the same as [abcdef]
- [!abc] is [d-Z]
- Job Control
- processes can be run in the background, or suspended
- The process is detached from the terminal
- If it attempts to perform i/o to the terminal it is suspended
- ctrl-z
- bg
- fg
- prog &
- jobs
- kill %d
- Command execution
- Simple Commands : words delimited by spaces
- ls -alrt a b c d
- Bash will identify the command (ls)
- And the arguments (-alrt a b c)
- And invoke the command with the arguments
- We will see how to do this later.
- Pipelines
- cmd arg arg | cmd arg arg ...
- The shell will send the output of the first command as input to the second command.
- We will see how to do this later
- Lists
- delimited by ;
- cmd1; cmd2; ...
- uptime; who
- cmd1 & cmd2
- cmd1 && cmd2
- cmd1 is executed
- If it has an exit status of 0 then cmd2 is executed
- cmd1 || cmd2, same but cmd1 returns non 0
- I/O redirection
- cmd > file (send stdout to file)
- cmd < file (get stdin from file)
- cmd 2> file (standard error to file.)
- cmd > file 2>&1 (both stdout and stderr to foo)
- cmd >> file (append stdout to file)
- cmd &>> file (append stdout and stderr to file)
- There is much more here, but this will do.
- Programming commands
- Variables, printenv
- loop and conditional structures
- functions
- Shells can be used to execute programs.
- But more on this to come.