我在写一个shell脚本。 我正在阅读的教程有这样的第一行:
#!/usr/bin/env bash/
但它不适合我 ( error : no such directory
)
如何找出我正在使用哪个bash,它位于哪里?
感谢您的任何build议和帮助。
非常感谢。 它现在有效 。
解决scheme是 #!/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
为什么这样? 它似乎可以读取重新启动的话。
谢谢你们! 我现在修好了
解决办法 :在unix中编辑文件(vim / nano,不pipe在windows下)
Thank again :)
你可以尝试下面的命令
which bash
在一个外壳。 然后放
#!<the output of which bash>
还有一种方法: echo $SHELL
。
如果你删除/
从bash/
,它应该工作。
要找出bash的位置,请发出以下命令:
type bash
在你的命令提示符下。 并确保它总是被你的脚本使用:
#!bash
这有一个问题,可能会被发现和使用,这可能是安全问题,但我已经这样做了多年。
删除行尾的多余字符。 不需要斜线, dos2unix yourscript
将删除不需要的CR。
#!/usr/bin/env bash
事实上,更好的是为你的重启问题开一个新的问题。 大多数情况下,您不在定义重新启动命令的目录或重新启动不在您的路径中。 尝试把整个路径。