UNIX TUTORIALS - Unix - Quoting Mechanisms
Unix - Quoting Mechanisms
ADVERTISEMENTS
Example:
Quoting | Description |
---|---|
Single quote | All special characters between these quotes lose their special meaning. |
Double quote | Most special characters between these quotes lose their special meaning with these
exceptions:
|
Backslash | Any character immediately following the backslash loses its special meaning. |
Back Quote | Anything in between back quotes would be treated as a command and would be executed. |
ADVERTISEMENTS
The Metacharacters:
* ? [ ] ' " \ $ ; & ( ) | ^ < > new-line space tabADVERTISEMENTSExample:
#!/bin/sh echo Hello; Word
Hello ./test.sh: line 2: Word: command not found shell returned 127
#!/bin/sh echo Hello\; Word
Hello; Word
#!/bin/sh echo "I have \$1200"
I have $1200The Single Quotes:
echo <-$1500.**>; (update?) [y|n]
echo \<-\$1500.\*\*\>\; \(update\?\) \[y\|n\]
echo '<-$1500.**>; (update?) [y|n]'
echo 'It\'s Shell Programming'The Double Quotes:
VAR=ZARA echo '$VAR owes <-$1500.**>; [ as of (`date +%m/%d`) ]'
$VAR owes <-$1500.**>; [ as of (`date +%m/%d`) ]
VAR=ZARA echo "$VAR owes <-\$1500.**>; [ as of (`date +%m/%d`) ]"
ZARA owes <-$1500.**>; [ as of (07/02) ]
echo 'It\'s Shell Programming'Example:
var=`command`Example:
DATE=`date` echo "Current Date: $DATE"
Current Date: Thu Jul 2 05:28:45 MST 2009