相关疑难解决方法(0)

bash 中的“eval”命令是什么?

你可以用eval命令做什么?为什么有用?它是 bash 中的某种内置函数吗?没有man它的页面。。

shell bash eval

261
推荐指数
7
解决办法
65万
查看次数

如何干净地添加到 $PATH?

我想要一种向 $PATH、系统范围内或单个用户添加内容的方法,而无需多次添加相同的路径。

想要这样做的一个原因是,可以在 中进行添加.bashrc,这不需要登录,并且在使用(例如)lightdm从不调用 的系统上也更有用.profile

我知道有关如何从 $PATH清除重复项的问题,但我不想删除重复项。我想要一种仅在路径尚不存在时添加路径的方法

shell path

35
推荐指数
5
解决办法
9032
查看次数

如何一次定义类似的bash函数

我有这些功能~/.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

10
推荐指数
2
解决办法
746
查看次数

命名的 bash 函数参数

一直想知道这一点,但从未完全调查过 - 有没有办法在 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)

bash shell-script

1
推荐指数
1
解决办法
5862
查看次数

标签 统计

bash ×3

shell ×2

eval ×1

path ×1

shell-script ×1