Study questions covering Unix Chapter 8 Flashcards
Unix Midterm part 3 of 3
Is it possible to execute a shell Bourne script if you are not given execute access permission? If yes, how?
Yes it is possible. You just need to execute the command
sh shell_script_name
Is it possible to execute a shell csh script if you are not given execute access permission? If yes, how?
Yes it is possible.
tcsh shell_script_name
What is the command that used to make a file an executable file?
chmod u+x schell_script_name
How do you debug a shell script?
To debug your program use -x or -xv when you invoke the shell.
ex. sh -x shell_script
In Bourne-style shells, what is the difference between the while and until loops?
while–do–done loops repeat statements as long as the while
condition is met
until–do–done loops repeat statements till the until condition is met
In Bourne-style shells, what is the command that used to read input from the standard input? Give an example
The read command reads one line of input from the standard input and assigns its
words to variables given as arguments.
read X
bob
echo $X
bob
In Bourne-style shells, what is the Unix command that adds two integer numbers? Give an example.
expr 5 + 2
In Bourne-style shells, what is the Unix command that multiplies two integer numbers? Give an example.
expr 5 * 6
need the \ because * is reserved for something else in UNIX
In Bourne-style shells, how do you compare two numeric values? Give an example.
[5 -lt 6]
- eq
- ne
- lt
- gt
- le
- ge
In Bourne-style shells, how do you compare two strings? Give an example.
test -z string
does string length = 0
test string = string2
test string != string2
Consider script.sh that contains the following script
#!/bin/sh
echo $0
Explain the output when you execute script.sh ABC
output would be ./script.sh because echo $0 echoes the filename of the current script
Write a Bourne shell script named LL that lists your current directory in a long format.
a. Execute LL using the sh command (i.e., sh ./LL)
b. How do you execute LL again without using sh command
a) sh LL
b) chmod u+x LL; LL
Write a Bourne script file that performs the following:
• Clearing the screen
• Showing the current date and time
• Showing the current number of users on the system
!/bin/sh
clear
date
w
In Bourne shell, if x=10, what you will get if you execute echo $x$x; echo x$x$
1010
x10$
What is the output of the following shell script? #!/bin/sh x=5 echo expr $x + 10 echo ”expr $x + 10” echo ’expr $x + 10’ echo `expr $x + 10`
expr 5 + 10
expr 5 + 10
expr $x + 10
15
Explain what happens when you execute the following commands: new_command=ls echo $new_command echo ”$new_command” echo ’$new_command’ echo `$new_command`
ls
ls
$new_command
#odd_prn# #what_is_ph.c# LL LL~ Lab3_script_outputs Working-Area a.out abc bup bup~ dir1 dir2 error error_file_1 error_file_2 folder hello hello.c hello.c~ hello2 lab5_1.c lab5_1.c~ lab5_2.c lab5_2.c~ lastarg letter.txt letter2.txt man numbas~ numbersfile nums nums~ odd_prn old_nums output_and_error_file_1 output_and_error_file_2 output_file_1 output_file_2 postMidnight postMidnight~ prn_triangle prn_triangle~ prog-A prog-B prog-C prog1 public_html script.sh simple.c test test.c test.c~ test1 test2 test~ vm what_is_ph.c
If you have a shell script called new_file as listed below:
#!/bin/sh # echo $0 echo $1 echo $# echo $*
shift
echo $0
echo $1
echo $#
echo $*
Explain what happens when you execute the following commands:
new_file a b c
new_file a 3 a b c new_file b 2 b c
Write a Bourne shell script called fi1e_checker that reads a filename from the standard input and produces the
properties of that file (e.g., exists, readable, executable).
#!/bin/sh file= read file if test -x "$file" ; then echo "$file" has execute permission. fi if [ -r $file ] ; then echo "$file" has read permission. fi if [ -s $file ] ; then echo "$file" exists. fi
Write a Bourne shell script called executable that lists the names of all executable files in the current directory.
grep –> search a file for a pattern
ls -al | grep “*”