是什么。/ example.sh`和'SH example.sh`之间`的区别 [英] What is the difference between `./example.sh` and `sh example.sh`
问题描述
我试图使用bash和阵列玩。但在执行一个示例脚本,我得到了一个意外的语法错误消息: example.sh:3:example.sh:语法错误:(意外
这是脚本。
#!/斌/庆典
阵列=(一二三)
如果我运行./example.sh它的工作原理,并显示没有错误的脚本。但是,如果我跑 SH example.sh
我收到错误消息。
我觉得这两个命令是一样的:
- SH example.sh
- ./ example.sh
所以...两者有什么区别呢?
ARRAY_NAME =(值1 ...值N)
这是如何只在初始化庆典
的数组。当您执行 ./ example.sh
,shebang行#!/斌/庆典
告诉系统使用庆典
执行
但是,当你执行 SH example.sh
, SH
用于执行。在许多Unix系统(如Linux), SH
等同于庆典
。这似乎 SH
为您的系统上不同的外壳。
I am trying to play with bash and arrays. But executing a sample script, I got an unexpected syntax error message: example.sh: 3: example.sh: Syntax error: "(" unexpected
. And this is the script
#!/bin/bash
array=( one two three )
If I run the script with ./example.sh it works and no errors are displayed. But if I run sh example.sh
I get the error message.
I thought that these two commands are the same:
- sh example.sh
- ./example.sh
so ... what is the difference between the two?
array_name=(value1 ... valuen)
This is how to initializes an array in bash
only. When you execute ./example.sh
, the shebang line #!/bin/bash
tells the system to use bash
to execute.
However, when you execute sh example.sh
, sh
is used to execute. In many Unix systems (like Linux), sh
is equivalent to bash
. It seems sh
is a different shell on your system.
这篇关于是什么。/ example.sh`和'SH example.sh`之间`的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!