Week 4 - Bourne Again Shell (Bash) Flashcards
(38 cards)
What is Bash?
A shell (command interpreter + programming language)
What standard does Bash and most Linux/Unix systems adhere to?
POSIX standard
Bash executes several files before you are in control what are some directories that these files reside in?
Why do we need to execute these files?
Login shell:
/etc/profile (global)
~/.bash_login
Non-login shell:
~/.bashrc
Non-login, non interactive:
BASH_ENV
We execute these files to setup the environment settings.
What command do we use to redirect standard error to a file?
2>
cat x y > hold 2 > errors
(2 = standard error,
1 = standard output,
0 = standard input,
& differentiates from file name)
What command do we use to redirect standard error to standard output?
2>&1
cat x y > hold 2>&1
(2 = standard error,
1 = standard output,
0 = standard input,
& differentiates from file name)
chmod u+x filename
What does u+x do?
Gives execution (x) privileges to the owner of the file (u)
The first token is always interpreted as a(n) _______
Command
What does # represent?
A shell comment
What does #! represent?
!/usr/bin/python3
“shebang” defines the interpreter used to run the script
print(“This is a Python script.”)
___ separates sequential commands on a line
;
What are the two uses of &
a& runs task in background
> &2 denotes standard error file descriptor instead of filename.
Why is a job a command pipeline?
Under the hood, a job is multiple commands with pipes:
command1 | command2 | command3
fg %jobnumber
kill %jobnumber
what is the % for?
% is used to refer to a job number
What does CTRL-Z do?
Suspends foreground job
What is a directory stack?
What command displays the stack?
Stores history of visited directories like a navigation stack.
dirs
Give an example of a variable
name=tommy_j2525
NOTE: No whitespaces and cannot start with a digit
What special character do we use to evaluate variables?
$
echo $myvar
What are some special parameters?
$0: The name of the script or command.
$#: The number of arguments passed to the script.
$@: All arguments passed to the script.
$?: The exit status of the last command.
$$ contains the process identification (PID)
$! contains the PID of the last process run in
background
What does the shift built-in do?
Shifts arguments to the left when you are using positional parameters.
What is the difference between a command and a built-in?
Commands are external scripts, built-ins are integrated into the shell.
What does the set builtin do?
assigns arguments to positional parameters
NOTE: set -v (verbose) is useful for debugging
What is the output for each? (person=alex)
echo person
echo $person
echo “$person”
echo ‘$person’
echo $person
person
alex
alex
person
person
What is the output for each?
(person=”alex and jenny”)
echo $person
echo “$person”
alex and jenny
alex and jenny
$ directly plops tokens into the command with positional arguments which results in only one space between the words
(echo alex and jenny)
$”” will directly output the original string from the variable
(echo “alex and jenny”)
memo=alex*
is
echo “$memo”
the same as echo $memo?
Why?
No
echo “$memo” will output alex* (the original string)
echo $memo will replace $memo with alex*
(echo alex*)
which performs string matching
output alex.report alex.summary