Linux and UNIX Shell Basics
Aaron Toponce
Linux Guru
Best viewed with a standards-compliant browser (not IE).
What is a shell?
- Provides system interface
- Sits between user and kernel
- Loaded at bootup until shutdown
- Resides in memory
- Contains built-in commands
Interactive vs. Non-interactive
- Interactive
- Prompts for input
- Processes user commands
- Non-interactive
- Shell scripts
- No user input
- System accounts
Login vs. Non-login
- Login
- Start non-login shells
- Sets the $PATH, $UID, $GID, $TERM variables
- /etc/profile, ~/.bash_profile
- /etc/bashrc, ~/.bashrc
- su --login, su -l, su -
- sudo -i
- GUI and tty
- Non-login
- gnome-terminal, new tabs, etc.
- $PATH, etc., not set
- /etc/bashrc, ~/.bashrc
- Changing shells
- su
- sudo -s
Available Shells
- cat /etc/shells
- aptitude search sh | grep -i shell
- Interactive: ash, bash, csh, dash, esh, ksh, pdksh, sh, tcsh, zsh
- Non-interactive: /bin/false, /usr/sbin/nologin
- Default login: cat /etc/passwd
- Change default: chsh
Subshells
- Commands nested with `` or $()
- EG: echo "Date is `date`"
- shell built-ins vs binaries
Programming Quickstart
- #!/bin/bash
- # denotes a comment
- Script is just shell commands
- if then else, if then elif else, case
- while do done
- for do done
Shell Variables
- env vs set
- export adds 'set' variables
- syntax: variable=value
- echo $variable
- alias
File Globbing
- Simple shell metacharacters
- Not the same as REGEX!
File Globbing Continued
- \ interpret the following characeter literally
- ; separate commands
- $ Substitute variables
- ? Match single character
- * Match zero or more characters
- [abc] Match for one character from set
- [a-c] Matches a range of characters
- [!abc] Don't match from set
- (cmds) Execute commands in subshell
- {cmds} Execute commands in current shell
Q&A
Any comments, questions or rude remarks?
[any material that should appear in print but not on the slide]