# 2.1 调用一个脚本

写完一个脚本以后，你可以通过`sh scriptname`或`bash scriptname`来调用它（不推荐使用`sh <scriptname`调用脚本，因为这会禁用脚本从标准输入（stdin）读入数据）。更方便的方式是使用`chmod`命令使脚本可以被直接执行。

执行命令：

`chmod 555 scriptname`（给予所有用户读取/执行的权限）

或

`chmod +rx scriptname`（给予所有用户读取/执行的权限）

`chmod u+rx scriptname`（仅给予脚本所有者读取/执行的权限）

当脚本的权限被设置好后，你就可以直接使用`./scriptname`进行调用测试了。如果脚本文件以sha-bang开头，那么它将自动调用指定的命令解释器运行脚本。

完成调试与测试后，你可能会将脚本文件移至`/usr/local/bin`（使用root权限）中，使脚本可以被所有用户调用。这时你可以直接在命令行中输入`scriptname [ENTER]`执行脚本。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.clay-wangzhi.com/shell/part1/02_starting_off_with_a_sha_bang/02_1_invoking_the_script.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
