Basic Scripting
Linux Essentials +
Chapter 11: Basic Scripting
Writing here
Questions and Answers
Q1
A file begins with #!/bin/csh. This means:Running the script will invoke /bin/csh to interpret the rest of the file
Q2
Which are appropriate editors for writing shell scripts?1. vi 2. nano
Q3
What does this shell script do? FOO=/tmp/foo if [ ! –d $FOO ]; then mkdir $FOO fiCreates /tmp/foo if it does not exist
Q4
Q5
Given the following part of a script: if [ -f $1 ]; then echo “I am here” fi What is the meaning of $1? It is the first argument passed to the script
Q6
Given the following script that is run through ./test.sh hello goodbye: if [ -f $2 ]; then echo "I am here" fi When will “I am here” be printed? If a file called "goodbye" exists in the current directory
Q7
What is the correct way to save the current directory to a variable?A=`pwd`
>Q8
What information is held inside $? ?The previous command’s exit code
Q9
The number of users logged in is in a variable called USERS. How would you test to see if there are 5 users logged in?test $USERS –eq 5
Q10
Given the following script: while [ ! –f /tmp/foo ]; do echo –n "." process_data > /tmp/foo done Which of the following are true?1. If a file called /tmp/foo exists, process_data won’t be run 2.