bash和sh和./的区别

bash和sh和./的区别

今天在执行一个脚本的时候,用的是sh script.sh,执行报错,使用bash script.sh执行时就能成功,才知道shbash是不一样的

sh

sh表示 Bourne Shell,是 Unix 系统上的一种基本的命令解释器。它也可以是其他 Shell 解释器的符号链接,如 Bash 或者其他类似的 Shell

但在某些系统上,sh 实际上可能是 bash 的符号链接,这个时候运行 sh script.sh 实际上会使用 Bash 来解释执行 script.sh 脚本

bash

bash是Bourne Again Shell 的缩写,是Bash shell的解释器。它是 Bourne Shell (sh) 的升级版本

可以在命令行中直接使用 bash 命令来启动一个交互式的 Bash shell,也可以通过 bash script.sh 这样的方式来执行一个 Bash 脚本

./

./在linux中表示当前目录。

在命令行中输入 ./script.sh 时,它告诉系统去当前目录找名为 script.sh 的文件并执行它

这种方法需要脚本具有执行权限,并且会使用脚本文件头部(#!)指定的解释器来执行脚本。如果没有指定解释器,将使用默认的shell解释器

这种文件需要添加可执行权限

复制代码
chmod +x script.sh
相关推荐
chao_78919 小时前
构建start_app.sh,实现快速启动项目
python·bash·终端·前后端
笨笨D幸福1 天前
应用程序重定向技术(Shim)
bash·scoop·shim
xuchaoxin13752 天前
bash@bash帮助命令help@bash命令可用选项设置@bash -c@set命令@set --
bash
ol木子李lo3 天前
Linux 命令备忘录
linux·运维·服务器·windows·编辑器·ssh·bash
dingdingfish4 天前
Bash学习 - 第10章:Installing Bash
bash·make·shell·install·configure·5.3
dingdingfish4 天前
Bash学习 - 第8章:Command Line Editing,第3节:Readline Init File
bash·init·bind·readline
dingdingfish5 天前
Bash学习 - 第8章:Command Line Editing,第6-8节:Programmable Completion
bash·shell·completion·complete·compgen·compopt
dingdingfish6 天前
Bash学习 - 第8章:Command Line Editing,第4-5节:Bindable Readline Commands
bash·emacs·vi·bind·readline
香芋Yu6 天前
【从零构建AI Code终端系统】02 -- Bash 工具:一切能力的基础
开发语言·bash·agent·claude
dingdingfish6 天前
Bash学习 - 第7章:Job Control
bash·shell·wait·job