Quoting +
in that context has not desired effect effect because it only tells zle
(zsh's command line editor) to take +
literally. The command alias
itself still recieves the string "+x" as first command line argument and thus tries to parse it as option.
If you pass the option --
to the alias
command, everything after it will be used as an argument, even if it starts with an +
or -
. To use your example:
alias -- +x='chmod +x'
alias -- -x='chmod -x'
Note: Many - but not all - other tools behave similarly, zsh built-ins as well as external commands. For example:
% touch -negative
touch: invalid option -- 'n'
Try 'touch --help' for more information.
% touch -- -negative
% ls -negative
ls: invalid option -- 'e'
Try 'ls --help' for more information.
% ls -- -negative
-negative
% rm -negative
rm: invalid option -- 'n'
Try 'rm ./-negative' to remove the file '-negative'.
Try 'rm --help' for more information.
% rm -- -negative
Of course, you can also do as rm
suggests and use ./-negative
in most (all?) of these cases where paths are involved.
One notable exception is GNU echo
. It is difficult to get it to print any options it recognizes without additional text. For example "-n":
% /bin/echo -n
% /bin/echo -- -n
-- -n
% /bin/echo -n -e '-n\n'
-n
\+
? most special characters in filenames must be escaped. that may make your alias clumbsy to use however. cyberciti.biz/faq/… this is imporant because Bash uses+
as a reserved operator: tldp.org/LDP/abs/html/special-chars.html Ultimately, I'm forced to conclude that using+
in an alias is a bad choice.\+x
as the alias.+
is an operator in shell, I was just wondering whether creating+x
alias is allowed, since trying to execute+x
raises a command not found error.alias +x='chmod +x'
works fine in bash; this is a zsh problem. @hjpotter92: This is a kludge, but if you get a "command not found" error when you type+x
, that suggests that you may be able to create a script called+x
in your private bin directory.