Bash Programming
Bash Programming
测验, 10 个问题
1
point
1。
Which of the following are requirements for variable names?
1
point
2。
What does the exit status of a program indicate?
The exit status of a program indicates the value that was computed by
the program.
1
point
3。
What is printed to the console by the following command?
Bash Programming
测验, 10 个问题 1 echo Demetrius || [[ 6 -eq 7 ]] || echo Helena &&
echo Hermia || [[ 7 -gt 4 ]]
1 Demetrius
2 Helena
1 Helena
2 Hermia
1 Demetrius
2 Hermia
1
point
4。
Consider the following program called numrange.sh:
Bash Programming
测验, 10 个问题 1 #!/usr/bin/env bash
2 # File: numrange.sh
3
4 odd=$(echo "$1 % 2" | bc)
5
6 if [[ $odd -eq 0 ]]
7 then
8 status="even"
9 else
10 status="odd"
11 fi
12
13 if [[ $1 -gt 0 ]] && [[ $1 -lt 10 ]]
14 then
15 location="in"
16 else
17 location="out of"
18 fi
19
20 echo "This number is $status and $location
range."
21
1 bash numrange.sh 6
2 bash numrange.sh 11
3 bash numrange.sh 400 10
1
point
5。
What is the result of the script below?
Bash Programming
测验, 10 个问题 1 lab=(jeff roger brian)
2 lab[3]=sean
3 lab=("${lab[*]}" "${lab[*]}")
4 echo ${#lab[*]}
1
point
6。
Consider the following program called reqseq.sh:
1 #!/usr/bin/env bash
2 # File: repseq.sh
3
4 sequence=$(eval echo {$1..$2})
5
6 for i in $sequence
7 do
8 compute=$(echo "$i % $3" | bc)
9 result="$result $compute"
10 done
11
12 echo $result
13
1 1 2 0 1 2 0 1 2 0
1 bash repseq.sh 1 9 3
1 bash repseq.sh 1 6 2
1 bash repseq.sh 1 9 2
Bash Programming
测验, 10 个问题
1 bash repseq.sh 1 6 3
1
point
7。
What's the purpose of the local keyword?
The local keyword ensures that all of the actions taken by a particular
function do not affect the global computing environment.
The local keyword stores the value of several variables locally so that
they can be accessed later on within a script.
The local keyword allows you to assign the value of a variable within a
function without changing the global value of that variable.
The local keyword allows you to create a function such that the
function can be used within your shell the same way you would use a
command.
1
point
8。
Which of the following are not part of the Unix Philosophy?
9。
What actions are taken by the following commands?
1
point
10。
What is one reason you might want to modify the PATH environmental variable?
The PATH can be modified in the bash profile which is where aliases
are defined. The bash profile is run every time you start a shell.
You can add a directory containing your own programs to the PATH
which allows you to access them on the command line.