例如,我想创建一个命令good night
,如下所示alias good night="many many many commands here"
。我试过,但不允许使用空格。有什么方法可以实现这个吗?
答案1
该函数应该可以帮助你入门:
good () {
if [ -z "$1" ]; then
echo "Perhaps you meant 'good night'?"
else
if [ "$1" = "night" ]; then
echo "GOOD"
echo "NIGHT"
echo "good"
echo "night"
echo "etc"
else
echo "ERROR: strange time detected: $1"
fi
fi
}
将其另存为,例如,good.sh
然后source
它:
. good.sh
good night
现在将执行各种命令(echo
用您想要的任何内容替换语句)。