

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Class: UNIX Operating Sys Fundamental; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Fall 2006;
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!
11/3/2006 3 Department of Com
puter and Informati
on Sciences
Shell: Turn Interpretation OffShell: Turn Interpretation Off
Backslash โ
Double quotes โ โ โ Single quotes โ โ โ
echo โ$HOMEโ โ$HOMEโ $HOME echo My files are: โ*โ echo โMy files are: *โ echo โMy files are: *โ
11/3/2006 4 Department of Com
puter and Informati
on Sciences
UABEffect of Quoting on Special Characters Effect of Quoting on Special Characters
newline NO NO NO ! YES NO NO
spaces NO NO NO
` (back quote) YES NO NO
โ (double quote) - NO NO
โ (single quote) NO - NO
$ YES NO NO
; NO NO NO
NO NO NO
| NO NO NO
< NO NO NO
{ } NO NO NO
[ ] NO NO NO
Character Inside โ โ Inside โ โ After \
11/3/2006 5 Department of Com
puter and Informati
on Sciences
SummarySummary
The backslash character and single quotes turn off interpretation for all special characters The double quotes turn off interpretation of all special characters except $, `, and \ (\ - only if the next character is interpreted)
The backslash character turns off interpretation for all special characters The single quotes turn off interpretation of all special characters except the! The double quotes turn off interpretation of all special characters except $, `, and!
11/3/2006 6 Department of Com
puter and Informati
on Sciences
Miscellaneous Miscellaneous
grep treats $ character as end of line (e.g., grep ';$' MyClass.java grep ';$' MyClass.java โ look for lines ending with ;)
echo โ โ$USERโ โ echo โ โ$USERโ โ echo โ$USERโ?โ $USER โ โ$USERโโ echo โ$USER \โ โDate is \โ date
\โ $USER *\โ
$ aa=t* $ echo $aa '$aa' "$aa" t.c t1.c temp.java tmp typescript $aa t*
$ aa=โtโ $ echo $aa '$aa' "$aa" t.c t1.c temp.java tmp typescript $aa t
11/3/2006 7 Department of Com
puter and Informati
on Sciences
$ echo ' $ echo 'HelloHello $USER$USER' Hello $USER $ echo "Hello $ echo "Hello $USER$USER"" Hello afgane
echo echo โ โn
11/3/2006 9 Department of Com
puter and Informati
on Sciences
Used for storing commonly used sequences of commands
So, a series of shell commands can be stored in a regular text file for later
execution
Before running a script, need to give it
execute permissions with chmod utility
11/3/2006 10 Department of Com
puter and Informati
on Sciences
When script is run, the system determines which shell the script was written for and then executes the shell using the shell as stdin The system knows which shell to use to execute the script by examining the first line of the script: If the first line is just a #, the script is interpreted by the shell from which it is executed If the first line is of the form #! pathName, then the executable program pathName is used to interpret the script If neither if the two rules apply, then the script is interpreted by a Bourne shell.
$ cat myScript.sh
echo โn The date today is date
$ cat myBashScript.sh #! /bin/bash
echo โn The date today is date
$ cat myDefaultScript.sh
echo โn The date today is date
11/3/2006 11 Department of Com
puter and Informati
on Sciences
Example: ./myscript arg1 arg2./myscript arg1 arg
$1 โ argument 1 $2 โ argument 2 and so on $0 โ the name of the current script $* โ all arguments $# โ no. of arguments $$ โ process id (PID) of process running the script
11/3/2006 12 Department of Com
puter and Informati
on Sciences
$ cat > cmdscript.sh echo 'The name of the script is: ' $ echo 'No. of command-line arguments = ' $# echo 'First three arguments are: ' $1 $2 $ echo 'Complete argument list is:' $* echo 'PID of this process = ' $$ $ chmod + cmdscript.sh
$ ./ cmdscript.sh โHello Worldโ โ$USERโ โ$USERโ _The name of the script is: ./cmdscript.sh No. of command-line arguments = 3 First three arguments are: Hello World afgane $USER Complete argument list is: Hello World afgane $USER* PID of this process = 5828_ $ ./ cmdscript.sh a b c The name of the script is: ./cmdscript.sh No. of command-line arguments = 3 First three arguments are: a b c Complete argument list is: a b c PID of this process = 5831