The simple way to do it is to use single quotes '…'
around the string. Single quotes delimit a literal string, so you can put it anything between them except a single quote '
. To insert a single quote in the string, use the four-character sequence '\''
(single quote, backslash, single quote, single quote).
Technically, there's no way to put a single quote inside a single-quoted literal. However consecutive literals are just as good as a single literal. 'foo'\''bar'
is parsed as
- the single-quoted literal
foo
- the backslash-quoted literal character
'
- the single-quoted literal
bar
This effectively means that '\''
is a way to escape a single quote in a single-quoted literal.
Note that the ksh print
command performs backslash expansion. Add the -r
option to avoid this. It won't hurt you because there happens to be no backslash in the string you want to print, but it's better to use -r
, in case a backslash is added during maintenance.
print -r -- 'clock=$(prtconf -s | awk '\''{print $4,$5}'\'')' > test.txt
Alternatively, you can use the POSIX method to print a string literally with a newline at the end:
printf '%s\n' 'clock=$(prtconf -s | awk '\''{print $4,$5}'\'')' > test.txt
clock=$(prtconf -s | awk '{print $4,$5}')
expression inawk
statement? – cuonglm Jun 10 '14 at 09:59