我如何知道我使用的是哪个shell?

时间:2022-03-24 06:19:08

I am writing a shell script. The tutorial that I am reading have the first line like this :

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

#!/usr/bin/env bash/

#!/ usr / bin / env bash /

but it isn't working for me. (error : no such directory)

但它不适合我。 (错误:没有这样的目录)

How can I find out which bash I am using and where is it located?

我怎样才能知道我正在使用哪个bash以及它位于何处?

Appreciate for any advice and help.

感谢任何建议和帮助。

Thanks a lot. It works now.

非常感谢。它现在有效。

solution is #!/usr/bin/env bash

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

Another problem: Why it just can't read the word 'restart'

另一个问题:为什么它只是无法读取'重启'这个词

my code in the start.sh:

我的代码在start.sh中:

#!/usr/bin/env bash/
RESTART="apachectl restart"
$RESTART

I does not work.

我不工作。

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

why is it like that? it seems that it can read the word restart.

为什么会那样?似乎它可以读取重启一词。

Thank you all! I have fixed it now.

谢谢你们!我现在修好了。

solution: edit the file in unix (vim/nano and whatever but not in windows)

解决方案:在unix中编辑文件(vim / nano以及Windows中的任何内容)

Thank again :)

6 个解决方案

#1


2  

You ca try the following command

您可以尝试以下命令

which bash

at a shell. Then put

在一个壳。然后把

#!<the output of which bash>

#2


15  

Yet another way: echo $SHELL.

还有另一种方式:回声$ SHELL。

#3


4  

If you remove the / from bash/, it should work.

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

#4


0  

To find out where bash is, issue the command:

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

type bash

at your command prompt. and to make sure it is always found by your script use:

在您的命令提示符下。并确保您的脚本始终可以找到它:

#!bash

this has the problem that some other bash may be found and used, which could be security issue, but I have been doing this for years.

这有一个问题,可能会找到并使用其他一些bash,这可能是安全问题,但我已经这样做了多年。

#5


0  

Remove the extra character(s) you have at the end of lines. No slash is required and dos2unix yourscript will remove the unwanted CRs.

删除行尾的额外字符。不需要斜杠,dos2unix yourscript将删除不需要的CR。

#!/usr/bin/env bash

#6


0  

Actually better would be to open a new question for your restart problem. Most probably you are not at the directory where the restart command is defined or restart is not in your path. Try putting the whole path.

实际上更好的是为你的重启问题打开一个新问题。很可能您不在定义restart命令的目录中,或者您的路径中没有重新启动。尝试整个路径。

#1


2  

You ca try the following command

您可以尝试以下命令

which bash

at a shell. Then put

在一个壳。然后把

#!<the output of which bash>

#2


15  

Yet another way: echo $SHELL.

还有另一种方式:回声$ SHELL。

#3


4  

If you remove the / from bash/, it should work.

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

#4


0  

To find out where bash is, issue the command:

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

type bash

at your command prompt. and to make sure it is always found by your script use:

在您的命令提示符下。并确保您的脚本始终可以找到它:

#!bash

this has the problem that some other bash may be found and used, which could be security issue, but I have been doing this for years.

这有一个问题,可能会找到并使用其他一些bash,这可能是安全问题,但我已经这样做了多年。

#5


0  

Remove the extra character(s) you have at the end of lines. No slash is required and dos2unix yourscript will remove the unwanted CRs.

删除行尾的额外字符。不需要斜杠,dos2unix yourscript将删除不需要的CR。

#!/usr/bin/env bash

#6


0  

Actually better would be to open a new question for your restart problem. Most probably you are not at the directory where the restart command is defined or restart is not in your path. Try putting the whole path.

实际上更好的是为你的重启问题打开一个新问题。很可能您不在定义restart命令的目录中,或者您的路径中没有重新启动。尝试整个路径。