Which characters are allowed in a bash alias

前端 未结 4 1726
北恋
北恋 2021-02-14 00:05

I recently added

alias ..=\'cd ..\'
alias ...=\'cd ../..\'
alias ....=\'cd ../../..\'

to my bash_aliases file. Playing around with this, I not

4条回答
  •  长情又很酷
    2021-02-14 00:36

    Bash aliases definitely cannot contain these characters: space , tab \t, newline \n, /, $, `, =, |, &, ;, (, ), <, >, ' and ".

    The GNU manual for bash https://www.gnu.org/software/bash/manual/html_node/Aliases.html says:

    The characters /, $, `, = and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

    "shell metacharacters" are defined in https://www.gnu.org/software/bash/manual/html_node/Definitions.html as

    A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: |, &, ;, (, ), <, or >.

    I couldn't find a list of "quoting characters" https://www.gnu.org/software/bash/manual/html_node/Quoting.html. As far as I know they are the single ' and double " quotes.

提交回复
热议问题