Week 5 Flashcards

1
Q

What are shell variables? How to use them?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are some of the frequently used shell variables?

A

$USERNAME
$HOME
$HOSTNAME
$PWD
$PATH

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to print all the environment variables?

A

printenv
printenv username
env
set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some of the special shell variables?

A

$0: name of the shell
$$: process ID of the shell
$?: return code of previously run program
$- flags set in the bash shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some of the process control commands?

A

fg
coproc
jobs
top
kill

echo $$

  • use of & to run a job in the background
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some of the frequently used program exit codes?

A

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>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are some of the shell options?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does echo command do?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to escape a shell variable?

A

echo “hostname is $HOSTNAME and user is $USERNAME”

does not print hostname but prints the username

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

how to escape alias?

A

setting alias:
alias date=’date -R’

escaping alias
\date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what are some of the process control commands

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly