> ## Content Index
> Fetch the complete content index at: https://isoziyuan.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# 将一组命令打包成一个 .sh 脚本文件
- URL: https://isoziyuan.com/p/100051/
- Published: 2023-03-13T22:41:14.000Z
- Updated: 2023-03-13T22:41:14.000Z
- Author: 9253462
- Tags: AI文章, old-wordpress-import, #wp, #wp-post, #Import 2026-09-04 23:28

将一组命令打包成一个 .sh 脚本文件非常简单。只需要在文件的开头添加以下内容：

```
#!/bin/bash

```

这个命令指定了脚本要使用的 shell。在这种情况下，它是 Bash shell。接下来，添加要运行的命令。例如，以下是一个简单的示例脚本，它将创建一个新的目录并在其中创建一个名为 my\_file.txt 的文件：

```
#!/bin/bash
mkdir my_directory
cd my_directory
echo "This is my file." > my_file.txt
```

保存脚本文件并设置其权限以允许执行：

```
chmod +x my_script.sh
```

现在，您可以通过运行以下命令来运行脚本：

```
./my_script.sh
```

当您运行此命令时，脚本将按照其定义执行其中的所有命令。