Menu

UNIX TUTORIALS - Unix - Quoting Mechanisms

Unix - Quoting Mechanisms

ADVERTISEMENTS

Example:

QuotingDescription
Single quoteAll special characters between these quotes lose their special meaning.
Double quoteMost special characters between these quotes lose their special meaning with these exceptions:
  • $
  • `
  • \$
  • \'
  • \"
  • \\
BackslashAny character immediately following the backslash loses its special meaning.
Back QuoteAnything in between back quotes would be treated as a command and would be executed.

ADVERTISEMENTS

The Metacharacters:

* ? [ ] ' " \ $ ; & ( ) | ^ < > new-line space tab

ADVERTISEMENTS

Example:

#!/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 $1200

The 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