bash -x 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10107124/
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
bash -x command
提问by Khiet
I saw a client doing $bash -x
command to see if the file is executable (or ksh -x
command, etc.) like the -x
in the if
statement in the shell script.
我看到一个客户端在执行$bash -x
命令以查看文件是否可执行(或ksh -x
命令等),就像shell 脚本-x
中的if
语句一样。
My question is: What does $bash -x
command do?
我的问题是:什么是$bash -x
命令吗?
My interpretation was to start a command in a new bash shell within the current shell, inheriting the same environment variables and executed by the same user.
我的解释是在当前 shell 中的新 bash shell 中启动命令,继承相同的环境变量并由相同的用户执行。
The funny thing is I can do $ls
but not $bash -x ls
, which give:
有趣的是我可以$ls
但不能$bash -x ls
,这给出了:
(under AIX 6)
/usr/bin/ls: /usr/bin/ls: cannot execute binary file
(在 AIX 6 下)
/usr/bin/ls: /usr/bin/ls: cannot execute binary file
It is a mystery for me why the error is - guessing it is due to a privilege which means my assumption above is not correct.
对我来说为什么错误是一个谜 - 猜测它是由于特权,这意味着我上面的假设是不正确的。
Also, I believe $bash ls
and $bash -x ls
is the same thing (-x
for "execute")?
另外,我相信$bash ls
和$bash -x ls
是同一件事(-x
对于“执行”)?
Any comments are greatly appreciated.
非常感谢任何评论。
Cheers!
干杯!
回答by user219882
The -x
option starts a BASH shell in tracing mode. You can see all the details of how your command/script is processed. It's a good way to find some bugs if your script does not do what you would expect to
该-x
选项以跟踪模式启动 BASH shell。您可以查看有关如何处理命令/脚本的所有详细信息。如果您的脚本没有按照您的预期运行,这是一种查找错误的好方法
And, just as Alex said in a comment, to run a command in BASH, you have to use -c
option like bash -x -c ls
.
而且,正如 Alex在评论中所说,要在 BASH 中运行命令,您必须使用-c
类似bash -x -c ls
.
See man bash
or the online manual, specifically the parts on invoking Bashand the set
builtin commandfor more information:
看到man bash
或在线手册,特别在部件上调用击和所述set
内置命令的详细资料:
All of the single-character options used with the
set
builtin (see The Set Builtin) can be used as options when the shell is invoked.
与
set
内置函数一起使用的所有单字符选项(请参阅设置内置函数)都可以在调用 shell 时用作选项。
-x
Print a trace of simple commands,
for
commands,case
commands,select
commands, and arithmeticfor
commands and their arguments or associated word lists after they are expanded and before they are executed. The value of thePS4
variable is expanded and the resultant value is printed before the command and its expanded arguments.
-x
在扩展之后和执行之前打印简单命令、
for
命令、case
命令、select
命令和算术for
命令及其参数或相关单词列表的痕迹。PS4
变量的值被扩展,结果值打印在命令及其扩展参数之前。
回答by Toby Speight
bash -x <file>
runs the script<file>
with tracing of each command executedtest -x <file>
tests whether<file>
has execute permissions for the current user.
bash -x <file>
运行脚本<file>
并跟踪执行的每个命令test -x <file>
测试<file>
当前用户是否有执行权限。
It appears that you have muddled these two.
看来你把这两个搞混了。