我对如何修改功能争论感到困惑:
我想:
bower ln
bower ln thing
执行:
bower link
bower link thing
这就像我得到的那样接近:
# ~/.bashrc
bower () {
if [[ $1 == "ln" ]]; then
${@[1]}="link"
echo "replacing" "$FUNCNAME" "$@"
fi
command "$FUNCNAME" "$@"
}
答案 0 :(得分:2)
使用set
命令:
bower () {
if [[ $1 == ln ]]; then
set -- link "${@:2}"
echo "replacing $FUNCNAME $@"
fi
command "$FUNCNAME" "$@"
}
但是,你真的不必替换第一个参数;你可以简单地在if
语句的正文中硬编码正确的参数:
bower () {
if [[ $1 == ln ]]; then
echo "replacing $FUNCNAME $first $@"
command "$FUNCNAME" link "${@:2}"
else
command "$FUNCNAME" "$@"
fi
}