Lect18 - Advanced Bash Flashcards

1
Q

What is Bash?

A

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been distributed widely as the default login shell for most Linux distributions and Apple’s macOS (formerly OS X). A version is also available for Windows 10

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

What are environment variables?

A

Bash stores a number of variables that control the way it operates. Some are system default. Many can be set by the user to adjust the operating environment. These can be displayed with the env command.

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

How can you display shell variables?

A

# echo $USER

or

# echo $LANG

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

How can you assign value to custom variable?

A

# fruit=apple

then

# echo $fruit

the variable is available ONLY in the current shell.

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

How can you make variable globally available?

A

# export fruit=apple

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

How can you substitute the output of a command for a variable

A

md5 = $(md5sum MyEvid.raw)

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

Show basic usage of a for loop?

A

$ for item in list

do

action on $item

done

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

Run a command for any txt file found?

A

for x in $(find . -name ‘*.txt’)

do

file $x

done

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

How can you execute multiple commands without interrupt?

A

echo 1; echo 2; echo 3;

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

How can you execute multiple commands, but only if preceding command is successful?

A

echo 1 && echo 2 && echo 3

dd if=/dev/sdh of=sdh.raw && md5sum sdh.raw

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

You want to view all pictures in a directory without having to use a separate command for each?

A

for pic in ./*
do
xv $pic
done

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