Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Linux 我如何知道我正在使用哪个外壳?_Linux_Shell - Fatal编程技术网

Linux 我如何知道我正在使用哪个外壳?

Linux 我如何知道我正在使用哪个外壳?,linux,shell,Linux,Shell,我正在写一个shell脚本。我正在阅读的教程的第一行如下: #/usr/bin/env bash/ 但这对我不起作用。(错误:没有这样的目录) 如何找出我正在使用的bash以及它的位置 感谢您的建议和帮助 非常感谢。它现在可以工作了 解决方案是#/usr/bin/env bash 另一个问题:为什么它不能读“重启”这个词 start.sh中的我的代码: #!/usr/bin/env bash/ RESTART="apachectl restart" $RESTART 我不工作 Usage: /

我正在写一个shell脚本。我正在阅读的教程的第一行如下:

#/usr/bin/env bash/

但这对我不起作用。(
错误:没有这样的目录

如何找出我正在使用的bash以及它的位置

感谢您的建议和帮助

非常感谢。它现在可以工作了

解决方案是
#/usr/bin/env bash

另一个问题:为什么它不能读“重启”这个词

start.sh中的我的代码:

#!/usr/bin/env bash/
RESTART="apachectl restart"
$RESTART
我不工作

Usage: /usr/local/apache2/bin/httpd [-D name] [-d directory] [-f file]
                                [-C "directive"] [-c "directive"]
                                [-k start|restart|graceful|graceful-stop|sto                                                                             p]
                                [-v] [-V] [-h] [-l] [-L] [-t] [-S]
Options:
-D name            : define a name for use in <IfDefine name> directives
-d directory       : specify an alternate initial ServerRoot
-f file            : specify an alternate ServerConfigFile
-C "directive"     : process directive before reading config files
-c "directive"     : process directive after reading config files
-e level           : show startup errors of level (see LogLevel)
-E file            : log startup errors to file
-v                 : show version number
-V                 : show compile settings
-h                 : list available command line options (this page)
-l                 : list compiled in modules
-L                 : list available configuration directives
-t -D DUMP_VHOSTS  : show parsed settings (currently only vhost settings)
-S                 : a synonym for -t -D DUMP_VHOSTS
-t -D DUMP_MODULES : show all loaded modules
-M                 : a synonym for -t -D DUMP_MODULES
-t                 : run syntax check for config files

要查找bash的位置,请发出以下命令:

type bash
在命令提示下。为了确保脚本始终可以找到它,请使用:

#!bash

这有一个问题,可能会发现并使用其他bash,这可能是安全问题,但我已经这么做了很多年。

如果您从
bash/
中删除
/
,它应该可以工作。

您可以尝试以下命令

which bash
在一个空壳里。然后把

#!<the output of which bash>
#!

还有另一种方法:
echo$SHELL

删除行尾多余的字符。不需要斜杠,并且
dos2unix-yourscript
将删除不需要的CR

#!/usr/bin/env bash

实际上,最好为重启问题打开一个新问题。 很可能您不在restart命令所在的目录下
已定义或重新启动不在您的路径中。试着把整个路径都放进去。

是的,我试过了。但是当I`./start.sh/`时,输出是`-bash:./start.sh:/bin/bash^M:错误的解释器:没有这样的文件或目录`^M。。塔达!你在windows中创建了该文件,对吗?unix文本文件与windows文本文件不兼容。。使用unix2dos转换它,或者只在linux中创建它。output
:没有这样的文件或目录
,我不确定是否正确。当我使用该命令时,它显示
bash是/bin/bash
,那么你的意思是我应该使用
#/bin/bash
@Newbie你当然可以使用它。我在运行脚本时使用了这个。它显示了
-bash:./start.sh:/bin/bash^M:糟糕的解释器:没有这样的文件或目录
@Newbie不知怎的,你在脚本中得到了回车符-你用什么编辑了它?巴特沃斯非常感谢。我知道现在哪里出了问题。由于我编辑它的方式,你是对的。谢谢
#!/usr/bin/env bash