sh 无需直接编辑bash文件即可添加别名。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 无需直接编辑bash文件即可添加别名。相关的知识,希望对你有一定的参考价值。

# function set_alias
#
# looks for the alias passed through $1 and $2 in file $3, and deletes it if it
# does exist, then appends to $3.
#
# $1 the name of the alias 
# $2 the command for the alias
# $3 (optional) the directory to store the aliases, defaults to ~/.bash_aliases
set_alias() {
    alias_name=$1
    alias_command=$2    
    
    [ -z $3 ] && alias_dir=~/.bash_aliases || alias_dir=$3
        
    if [ ! -f $alias_dir ]; then
        touch $alias_dir
        echo "# Custom aliases." >> $alias_dir
    fi      

    # See if the alias already exists. If it does, delete it.
    sed -i "/$alias_name/d" "$alias_dir"

    # Append the alias to the end of the file
    sed -ie "\$a alias $1='$2'" "$alias_dir"

    # Set it for this bash instance also.
    alias "$alias_name=$alias_command"
}

以上是关于sh 无需直接编辑bash文件即可添加别名。的主要内容,如果未能解决你的问题,请参考以下文章

Git bash如何调用不同版本的python

Git bash如何调用不同版本的python

如何让shell脚本变成可执行文件

bash特性-命令历史命令行编辑

sh 从bash终端删除所有heroku应用程序 - 无需脚本文件

sh 从bash终端删除所有heroku应用程序 - 无需脚本文件