Download presentation
Presentation is loading. Please wait.
1
Chapter 6 Dealing with quotes
2
Dealing with Quotes and slashes grep Susan phonebook grep Susan Goldberg phonebook results in an error grep ‘Susan Goldberg’ phonebook allows the shell to ignore spaces the single quote ignores the $ sign and * symbol
3
Double quotes Some things in double quotes are NOT ignored – in other words the shell WILL interpret $ signs back quotes (on the tilde key) backslashes other double quotes newlines
4
Examples $x=* $echo $x addresses intro lotaspaces nu names $echo ‘$x’ $x $echo “$x” *
5
Hiding quotes with quotes double quotes hide single quotes and single quotes hide double quotes $x=“’Good day, ‘ she said” $echo $x ‘Good day, ‘ she said $y=‘ “Good quotes are hard to find” ‘ $echo $y “Good quotes are hard to find”
6
The Backslash the backslash serves as a way of putting quotes around the next character $echo \\ \ $echo ‘\’ \
7
The Backslash (cont’d) The backslash goes as far as causing the shell to ignore a hard return this is useful for typing in long commands $lines=command1\ >command2 $echo $lines command1command2
8
The Back Quote this is used to tell the shell to execute the following command $echo The date and time is `date` The date and time is Wed Jan 24 14:20:34 PST 2007 be aware that this typically is no longer the preferred method, but you may run across it
9
The $(…) or command substitution Construct $echo “The date and time is: $(date)” The date and time is Wed Jan 24 14:20:34 PST 2007 keep in mind that within single quotes the command substitution construct does not work, but in double quotes it does
10
Examples echo There are $(who | wc – l) users logged in with single quotes echo ‘$(who | wc –l) tells how many users are logged in’ with double quotes echo “You have $(ls | wc – l) files in your directory
11
more $(…) stuff to preserve newlines / hard returns use double quotes $filelist=$(ls) $echo $filelist – yields everything on one line $echo “$filelist” – yields the files on separate lines
12
Nifty stuff to put the contents of a file into a variable use the cat command $namelist=$(cat names1) $echo “$namelist” - will list all the names with newlines mail $(cat unames) < memo – will email the memo to all users listed in unames who are on your system
13
Nested commands $filename=/usrs/steve/memos $firstchar=$(echo $filename | cut –c1) $filename=$(echo $filename | tr “$firstchar” “^”) $echo $filename ^usrs^steve^memos can also be written as
14
Nested commands (cont’d) $filename=/usrs/steve/memos $filename=$(echo $filename | tr “$(echo $filename | cut –c1)” “^”) $echo $filename
15
The expr operator used by older systems – only does integer arithmetic $expr 1 + 2 3 $ some quirks expr 17 * 6 - yields an error expr “17 * 6” - yields 17 * 6 expr 17 \* 6 – yields 102
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.