I am trying to make a file with special characters. But I don't want to use double or single quotes.
How can I make the file ?
I am trying to make a file with special characters. But I don't want to use double or single quotes.
How can I make the file ?
Backslash provides with another form of quoting in Bourne-like shells, so you can do:
printf %s \$\ \; > file
For instance to have file contain those 3 ($
, space and ;
) special characters. You can also use octal sequences in printf
to specify exact byte values:
printf \\1\\2 > file
Makes a file with bytes 1 and 2. Some printf
implementations also support hex sequences:
printf \\xff\\x80 > file
Or specifying characters with their Unicode code point:
printf \\u20ac > file
For the euro sign for instance. In most implementations, the character will be output in the locale's character set. An exception is the printf
builtin of ksh93
which outputs it in UTF-8 regardless of the locale's charset.
See also here documents for another way to enter text. That's convenient for multi-line text:
cat << \EOF > file
some text with $ \ | # *
and anything you want
EOF
To create file names with such characters, use:
echo text > \$\ \;
or:
echo text > $(printf \\1\\2)
etc. Note that as $(...)
is subject to split+glob, you need to disable it with:
IFS=; set -o noglob
For characters that are otherwise in $IFS
or glob operators (*
, ?
, [...]
).