我正在尝试创建一个脚本别名,如下所示:
第一个脚本的输出:
我正在尝试在脚本中创建一个别名,代码如下:
#!/bin/bash
shopt -s expand_aliases
#Currently just using 'git' to try and get it working
#It'll be replaced with the following line when it works
#compgen -c | while read x;
echo 'git' | while read x;
do
a=`echo $x | tr '[:lower:]' '[:upper:]'`;
echo $a;
echo $x;
if [ "$a" != '' ]
then
echo 'got here';
alias $a=$x;
alias;
GIT;
fi
done
虽然一个简单的测试脚本可以工作(testme
已经添加到当前shell的别名中):
#!/bin/bash
shopt -s expand_aliases
alias testme="echo It Worked"
alias
testme
第一个脚本的输出:
GIT
git
got here
alias GIT='git'
alias grep='grep --colour=auto'
alias ls='ls --color=auto'
GIT: command not found
GIT
出现在别名中,但无法执行。我尝试使用 . ./script.sh
和 source script.sh
调用它。我做错了什么?