Reputation:
In bash I have
$ echo -e -
-
$
But I get this in zsh:
$ echo '-'
$ print '-'
$
It seems that this is no substitution like that of ~
, etc.
Is this feature documented somewhere? And what is the simplest way to print a single -
character if I want to do that?
Upvotes: 0
Views: 189
Reputation: 18339
Generally a single -
has no special meaning in zsh
. But this is specific to zsh
insofar that echo
and print
are both built-ins of zsh
(echo
is also a built-in of bash
, but behaves slightly different there - obviously).
A single -
denotes that any arguments following it are not to be handled as options. This allows for example to output -E
with echo
instead enforcing BSD style echo
behavior:
% echo -E 'f\x6f\x6fbar'
f\x6f\x6fbar
% echo - -E 'f\x6f\x6fbar'
foobar
For print
this is documented in the zshbuiltins
manpage. Unfortunatelly it seems to be undocumented for echo
.
Following this, the easiest way to output a single -
(in zsh
) is probably to pass two of it to echo
or print
:
% echo - -
-
% print - -
-
The first -
also disables parsing any further -
as options.
Upvotes: 1
Reputation: 20843
Using printf
is more portable and will work more reliable than echo
. Try
$ printf '%s\n' -
-
Upvotes: 0