Q3 1-37 Flashcards
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 commandsh 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 metuntil–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 Xbobecho $Xbob
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 * 6need 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 stringdoes string length = 0test string = string2test 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 LLb) 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/shcleardatew
In Bourne shell, if x=10, what you will get if you execute echo $x$x; echo x$x$
1010x10$
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 + 10expr 5 + 10expr $x + 1015