"alias: =: not found",别名未定义,在 .bashrc 中有 "alias ll = 'ls -l'"
"alias: =: not found", and alias not defined, with "alias ll = 'ls -l'" in .bashrc
我在 Mac OSX 并尝试在 .bashrc 中添加一些基本别名(例如 alias ll = 'ls -l'
)。我在 .bash_profile 中获取 .bashrc,并且在启动时它识别出我在 .bashrc 中的一个函数。但是,每次添加别名然后尝试启动它时,我都会收到以下错误消息:
-bash: alias: ll: not found
-bash: alias: =: not found
-bash: alias: ls -l: not found
ll 别名不起作用,但以下函数声明的命令起作用:
#!/bin/bash
# prints the input
function print_my_input() {
echo 'Your input: '
}
创建普通别名还需要执行其他步骤吗?
试试这个:
alias ls='ls --color=auto'
alias ll='ls -l'
alias la='ls -la'
alias cd..='cd ..'
alias ..='cd ..'
在分配变量和别名时,Bash 不允许在 =
符号前后使用 space。
在旁注中,有两种方法可以声明一个函数:
使用关键字function
表示函数声明
function myfunction { # function is a keyword
echo hello
}
或者简单地在函数名后加上大括号并省略 function
关键字
myfunction() { # () indicate a function definition
echo hello
}
同时使用两者不是错误而是多余的。此外,Charles Duffy 在评论中指出:
...not just redundant, but also needlessly nonportable. myfunction() {
is guaranteed to work on all POSIX shells; function myfunction { works
on old ksh (and is supported in bash for compatibility with same);
combining the two doesn't work on baseline-POSIX or on old ksh.
我在 Mac OSX 并尝试在 .bashrc 中添加一些基本别名(例如 alias ll = 'ls -l'
)。我在 .bash_profile 中获取 .bashrc,并且在启动时它识别出我在 .bashrc 中的一个函数。但是,每次添加别名然后尝试启动它时,我都会收到以下错误消息:
-bash: alias: ll: not found
-bash: alias: =: not found
-bash: alias: ls -l: not found
ll 别名不起作用,但以下函数声明的命令起作用:
#!/bin/bash
# prints the input
function print_my_input() {
echo 'Your input: '
}
创建普通别名还需要执行其他步骤吗?
试试这个:
alias ls='ls --color=auto'
alias ll='ls -l'
alias la='ls -la'
alias cd..='cd ..'
alias ..='cd ..'
在分配变量和别名时,Bash 不允许在 =
符号前后使用 space。
在旁注中,有两种方法可以声明一个函数:
使用关键字function
表示函数声明
function myfunction { # function is a keyword
echo hello
}
或者简单地在函数名后加上大括号并省略 function
关键字
myfunction() { # () indicate a function definition
echo hello
}
同时使用两者不是错误而是多余的。此外,Charles Duffy 在评论中指出:
...not just redundant, but also needlessly nonportable. myfunction() { is guaranteed to work on all POSIX shells; function myfunction { works on old ksh (and is supported in bash for compatibility with same); combining the two doesn't work on baseline-POSIX or on old ksh.