Linux Chapter 9 - Bash Shell Scripting - Part A
No such file or directory hello world
Assume that xfile does not exist and yfile contains the string "hello world", under the Tcsh, what are the contents of the hold file after executing the following command? cat xfile yfile >& hold
can be executed with the command: /bin/bash testscript
Assuming that execute permission for a shell script named: "testscript" has not been set (turned on), then the script:
Both B and C.
Given the following bash shell statement: if [[ $# -eq 0) || $# -gt 0 ]] then echo "Usage: $0 ordinary file" exit 1 endif what condition will cause the echo command to be executed?
Response A or B will work.
Given the following block of code in a bash shell script: #EXAMPLE C option = $1 case "$option" d|D) date ;; l|L) ls ;; w|W) who ;; q|Q) exit 0 ;; esac What value of $option will cause the date to be displayed?
When $yourguess is not equal to $secretcode.
Given the following code segment in a bash shell script, while [ "$secretcode" != "$yourguess" ] do echo "Good guess but try again!" read -p "Enter your guess: " done What will cause the loop to continue?
it will be equal to customers.
Given the following statement, in bash Shell script: "demo1": if [ -f "$1" ] then filename = "$1" fileinfo = `ls -il $filename` fi What will be the value of $filename if the following command line is entered? demo1 customers addresses
7
Given, the following bash shell commands, what is the output of the following commands ? buffer = (6 9 3 7 2 4 8 1) echo ${buffer[3]}
Both B and C are correct. That is either: run the script with "/bin/bash scriptname" where scriptname is the name of the script. or inserting #! /bin/bash as the first line in the script.
How can you be certain to execute a bash shell in a script?
Enter CONTROL-C
How can you interrupt the following script? #!/bin/bash trap 'echo Program Interrupted; exit 1 INT while true do echo "Program running." sleep 1 done
the line is treated as a comment
If the first character on a line in a shell script is a #, the:
$#
In the bash shell, the total number of command line arguments is stored in variable:
Helps prevent overwriting files.
The bash shell command set -o noclobber
Displays output of the who command through the more pipe.
The command: echo `who | more`
The working directory when you login.
The environment variable: HOME contains the absolute pathname of:
$1
The first argument on the command line when executing a bash shell script is stored in the variable:
all of the above
The purpose of the following line in a bash shell script: #!/bin/bash is to:
that the bash shell is an extended version of the bourne shell.
The relationship between the bourne shell and the bash shell is:
allows the use of a filename as an argument to cd.
The variable: CDPATH
none of the above
What are "builtin" commands?
username="George W. Bush"
What bash command will create variable username and assign it the value of "George W. Bush"?
nohup myshellscript &
What command allows you to logout without terminating "myshellscript" running as a background process.
unset country
What command will remove variable: country ?
all of the above
What does the following command in .bash_profile (or .profile) do? if [ -f ~/.bashrc ] then . ~/.bashrc fi
Globbing refers to the process of interpreting ambiguous file references and substituting the appropriate list of file names>
What is globbing?
The values of the first five command line arguments.
What is the output of the following script? #!/bin/bash #display_args echo "$1 $2 $3 $4 $5" #end of script
reads one one line from stdin into variable "line".
What is the result of the following Shell command? read -p "Enter a line of text: " line
variable name is created with value of John.
What is the result of the following Shell command? name = John Doe II
PWD
What shell environmental variable is set equal to the path of the current working directory?
none of the above
When using the bash shell, values can be assigned to shell variables with the command:
export city
Which command is used to make a variable named "city", globally recognized by all shells created under the login shell?