bash 从 bash_profile 运行 shell 命令时出现“需要文件名参数”警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28965890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Filename argument required" warning when running shell command from bash_profile
提问by RobertAKARobin
I'm customizing my .bash_profile in my Mac's Terminal. I want to make a function that either runs a ruby file or opens it in a text editor, depending on my arguments.
我正在 Mac 的终端中自定义我的 .bash_profile。我想根据我的参数创建一个运行 ruby 文件或在文本编辑器中打开它的函数。
I'm very new to doing anything more with Terminal than just installing stuff.
我很新,除了安装东西之外,还可以用 Terminal 做更多的事情。
Here's what I've got so far:
这是我到目前为止所得到的:
scratchpad(){
if [ = run ]; then
ruby ~/Programming/ruby/scratchpad.rb
.
else
open -a ~/Programming/ruby/scratchpad.rb
.
fi
}
It works, successfully opening or running the script, but it gives me this error:
它有效,成功打开或运行脚本,但它给了我这个错误:
-bash: .: filename argument required
.: usage: . filename [arguments]
回答by Ian Roberts
Remove the .
lines:
删除.
行:
scratchpad(){
if [ = run ]; then
ruby ~/Programming/ruby/scratchpad.rb
else
open -a ~/Programming/ruby/scratchpad.rb
fi
}
In the shell, .
is a builtin command in its own right, an alias for "source", which is used to read in a shell script and execute its commands in the current shell rather than spawning a subshell, typically used for scripts that set environment variables that you want to use later
在shell中,.
它本身就是一个内置命令,是“source”的别名,用于读入shell脚本并在当前shell中执行其命令而不是产生子shell,通常用于设置环境的脚本以后要使用的变量
. set_env.sh
The error message you get is complaining that you haven't provided the file name argument that the .
command expects.
您收到的错误消息是抱怨您没有提供.
命令所需的文件名参数。