本文介绍了"alias:=:not found"和未定义别名,别名为"alias ll ='ls -l'".在.bashrc中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac OSX上,尝试在.bashrc中放入一些基本别名(例如 alias ll ='ls -l').我从.bash_profile中获取.bashrc,在启动时它可以识别我在.bashrc中具有的功能.但是,每次添加别名然后尝试启动它时,都会收到以下错误消息:

I'm on Mac OSX and trying to put some basic aliases in .bashrc (e.g. alias ll = 'ls -l'). I sourced .bashrc in .bash_profile, and on startup it recognizes a function that I have in .bashrc. However, I get the following error messages every time I add an alias and then try to start it up:

-bash: alias: ll: not found
-bash: alias: =: not found
-bash: alias: ls -l: not found

ll别名不起作用,但是以下函数声明的命令起作用:

The ll alias does not work, but the command declared by the following function does:

#!/bin/bash
# prints the input
function print_my_input() {
  echo 'Your input: ' $1
}

我还需要执行其他步骤来创建普通别名吗?

Is there an additional step I need to do to create normal aliases?

推荐答案

尝试以下方法:

alias ls='ls --color=auto'
alias ll='ls -l'
alias la='ls -la'

alias cd..='cd ..'
alias ..='cd ..'

在分配变量和别名时,

Bash不允许在 = 符号前后添加空格.

Bash does not allow a space before and after an = sign when assigning variables as well as aliases.

在旁注中,有两种方法来声明函数:

On a sidenote, there are two ways to declare a function:

使用关键字 function 表示函数声明

Using the keyword function to indicate a function declaration

function myfunction { # function is a keyword
    echo hello
}

或通过简单地在函数名称后加上花括号并省略 function 关键字

or by simply putting braces after the function name and omitting the function keyword

myfunction() { # () indicate a function definition
    echo hello
}

同时使用这不是一个错误,而是多余的.此外, Charles Duffy 在评论中指出:

Using both is not an error but redundant. Furthermore, Charles Duffy points out in the comments:

这篇关于"alias:=:not found"和未定义别名,别名为"alias ll ='ls -l'".在.bashrc中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 01:55