我有这些功能~/.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) 假设我将程序的STDOUT,重定向STDERR到文件。
./script.sh 1> output.log 2> error.log
Run Code Online (Sandbox Code Playgroud)
正在运行的程序能否找到这个,即知道这些文件的路径?
我有一个 bash 脚本,它应该接受一些参数,然后在不同的用户中运行: test.sh
#!/bin/bash
sudo su user2 <<'EOF'
echo $1
EOF
Run Code Online (Sandbox Code Playgroud)
但是它打印空白:
$ ./test.sh haha
Run Code Online (Sandbox Code Playgroud)
我知道这是因为环境变量被重置(?)。我怎样才能通过这个论点?安全方面我听说我不应该禁用环境重置。我想到解决这个问题的唯一方法是写入$1文件,然后由 user2 再次读取它。但我想应该有更好的方法。