你可以用eval命令做什么?为什么有用?它是 bash 中的某种内置函数吗?没有man它的页面。。
我想要一种向 $PATH、系统范围内或单个用户添加内容的方法,而无需多次添加相同的路径。
想要这样做的一个原因是,可以在 中进行添加.bashrc,这不需要登录,并且在使用(例如)lightdm从不调用 的系统上也更有用.profile。
我有这些功能~/.bashrc:
function guard() {
if [ -e 'Gemfile' ]; then
bundle exec guard "$@"
else
command guard "$@"
fi
}
function rspec() {
if [ -e 'Gemfile' ]; then
bundle exec rspec "$@"
else
command rspec "$@"
fi
}
function rake() {
if [ -e 'Gemfile' ]; then
bundle exec rake "$@"
else
command rake "$@"
fi
}
Run Code Online (Sandbox Code Playgroud)
如您所见,这些功能非常相似。我想一次定义这 3 个函数。有没有办法做到?
环境
bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Run Code Online (Sandbox Code Playgroud) 一直想知道这一点,但从未完全调查过 - 有没有办法在 bash 中获取命名参数?
例如,我有这个:
function ql_maybe_fail {
if [[ "$1" == "true" ]]; then
echo "quicklock: exiting with 1 since fail flag was set for your 'ql_release_lock' command. "
exit 1;
fi
}
Run Code Online (Sandbox Code Playgroud)
是否有可能将它转换为这样的东西:
function ql_maybe_fail (isFail) {
if [[ "$isFail" == "true" ]]; then
echo "quicklock: exiting with 1 since fail flag was set for your 'ql_release_lock' command. "
exit 1;
fi
}
Run Code Online (Sandbox Code Playgroud)