Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
写#/bin/bash-x位于第一行,但在执行过程中没有获取任何信息_Bash - Fatal编程技术网

写#/bin/bash-x位于第一行,但在执行过程中没有获取任何信息

写#/bin/bash-x位于第一行,但在执行过程中没有获取任何信息,bash,Bash,写#时/bin/bash-x在bash文件(例如test.sh)的第一行中,我希望看到一些执行信息,但什么也得不到。。。此外,当我使用bash-x test.sh命令运行bash文件时,它将显示信息。 对发生的事情有什么帮助吗 非常感谢 要在脚本中将调试设置为打开,您需要使用set-x,因此: #!/bin/bash set -x ....... 仅当您直接执行文件时,shebang才适用: myfile ./myfile /path/to/myfile 如果改为执行解释器,则将使用该解

#时/bin/bash-x
在bash文件(例如test.sh)的第一行中,我希望看到一些执行信息,但什么也得不到。。。此外,当我使用
bash-x test.sh
命令运行bash文件时,它将显示信息。 对发生的事情有什么帮助吗


非常感谢

要在脚本中将调试设置为打开,您需要使用set-x,因此:

#!/bin/bash

set -x

.......

仅当您直接执行文件时,shebang才适用:

myfile
./myfile
/path/to/myfile
如果改为执行解释器,则将使用该解释器,无论它是否正确且与脚本兼容。因此,最佳做法是避免以下任一情况:

bash myfile
sh myfile

如果不使用
bash-x test.sh
,如何运行脚本?您使用的是
bash-test.sh
,还是
/test.sh
?是的,第一个答案准确地解释了原因。结果表明“#!/bin/bash-x”也有效。我尝试了另一个人的建议,成功了。谢谢