Week 5 Flashcards
What are shell variables? How to use them?
Most useful for communication between processes. (not using the file system). Shell variables are accessible only in the shell.
Display the shell vairables using echo command
echo hello world
echo $HOME
What are some of the frequently used shell variables?
$USERNAME
$HOME
$HOSTNAME
$PWD
$PATH
How to print all the environment variables?
printenv
printenv username
env
set
What are some of the special shell variables?
$0: name of the shell
$$: process ID of the shell
$?: return code of previously run program
$- flags set in the bash shell
What are some of the process control commands?
fg
coproc
jobs
top
kill
echo $$
- use of & to run a job in the background
What are some of the frequently used program exit codes?
0: success
1: failure
2: misuse
126: Command cannot be executed
127: command not found
130: processes killed using control + C
137: processes killed using kill -9 <pid></pid>
what are some of the shell options?
h: locate and hash commands
B: brace expansion enabled
i: interactive mode
m: job control enabled
H: !style history substitution enabled
s: commands are read from stdin
c: commands are read from arguments
What does echo command do?
prints space delimited text when no quotes are given. If single quote is opened with echo then it takes all text till the closing single quote. Same goes for double quotes as well.
how to escape a shell variable?
echo “hostname is $HOSTNAME and user is $USERNAME”
does not print hostname but prints the username
how to escape alias?
setting alias:
alias date=’date -R’
escaping alias
\date
what are some of the process control commands
ps : list processes currently running
ps -f : lists processes along with parent processes
ps -e : lists all process (including OS) currently running.
ps -ef: list all processes with parent process IDs
ps –forest : displays parent and child processes using a tree diagram