Bash Shell Flashcards

1
Q

Variable and function syntax

A
FOO=bar
VAR2=/home/user/docs
function yo()
{
  echo "yo"
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List of all exported shell variables

Command used to allow child sessions to use env vars

A
  1. export
  2. export FOO=bar
  3. export PATH=$PATH:/home/user/programs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Show environment vars

A

env

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

List shell settings or shell vars and funcs for the session

A

set
set -x/set +x- turn on/off she debugging
set -f -enable file globbing
set +f -disable file globbing

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

Remove var or function

A

unset -f yo

unset FOO

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

Display shell options

Modify shell options

A

shopt
shopt -s histreedit- set
shopt -u histreedit -unset

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

Locate an app file listed in $PATH

A

which bash

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

Determine if something is a function, file, alias, built-in or keyword

A

type cd=> function

type type=> built-in

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

Interactive login shell

A

/etc/profile=>/etc/profile.d/*

info from /etc/profile.d/ returns back to /etc/profile=>~/.bash_profile or ~/.profile =>~/.bashrc=>/etc/bashrc

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

Interactive non-login shell

A

~/.bashrc=>/etc/bashrc

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

First file read on login session. Sets env vars such as PATH, umask, bash history controls

A

/etc/profile

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

Configs of system-wide functions and aliases

A

/etc/bashrc

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

Templates of files that are added when an account is created

A

/etc/skel

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

Legacy ~/.bash_profile file

A

~/.bash_login

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

Set alias

A

vim ~/.bashrc
alias ll=”ls -la”
source ~/.bashrc or . ~/.bashrc

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

Run command from history

A

!56

run 56 line from history

17
Q

Location of history

A

~/.bash_history

18
Q

Env var keeping size of line in .bash_history

A

HISTFILESIZE

19
Q

Man pages

A
  1. exec programs and shell commands
  2. system calls- function provided by kernel
  3. library calls
  4. special files typically found in /dev
  5. files formats and conventions
  6. games
  7. miscellaneous
  8. for sysadmins
  9. for non-standard kernel routines
20
Q

Get pid of current bash process

A

echo $$

21
Q

Expand escaping chars to be printed in echo example

A

echo -e “This is an example of \n escaping chars \t\t !!”

22
Q

Exit codes

A

0= no issue
!=0 -issue
1. execute any command
2. echo $? to get exit value

23
Q

Conditional statements

A

!/bin/bash

var=$1
if [ $var == 1 ]
then
    echo  "$var eq one"
fi
if [ $var -ne 2 ] && [ $var -ne 1 ]
then 
    echo "$var equals 3"
fi

case $var in
1)
echo “in this case the positional parameter eq 1”
;;
2)
echo “in this case the positional parameter eq 2”
;;
3)
echo “in this case the positional parameter eq 3”
;;
esac

24
Q

Loops

A

!/bin/bash

for i in {1..5}
do
echo $i
done

echo 'for loop is complete'
counter=6
while [ $counter -le 9 ]
do
    echo $counter
    counter=$[ $counter+1 ]
done

echo ‘while loop is complete’

number=10
until [ $number -eq 15 ]
do
    echo $number
    ((number++))
done
25
Q

Positional parameters to be set into the script

A

!/bin/bash

set – first1 second1 third1

echo “the first arg is $1”
echo “the second arg is $2”
echo “the third arg is $3”

echo “the name of the script is $0”