# 自己寫吧！Hello,Bash：echo

寫任何程式語言的第一個入門，都是 say hello

進入Bash shell命令行，輸入&#x20;

```
echo "Hello, World"
```

<div align="left"><img src="/files/-LujIunJ3QcFJ4zlErzU" alt=""></div>

把上述命令寫成可執行檔，並以.sh為結尾，如hello.sh

```
#!/bin/bash
#第一個shell程式
echo "Hello, World"
```

chmod +x hello.sh

執行 ./hello.sh

在Windows上編輯script，這將產生Bash無法處理的不正確的行尾字符，一個常見的症狀是: command not found，此時需要安裝dos2unix，可以使用dos2unix程序修復script

## echo顯示帶顏色，需要使用參數-e&#x20;

格式: echo -e "\033\[字背景顏色;文字顏色m 字串 \033\[0m"

### **每種顏色都有對應的顏色碼。比如:重置=0,黑色=30,紅色=31,綠色=32,黃色=33,藍 色=34,洋紅-35,青色-36,白色-37。字顏色:30<=>37**

```
echo -e "\033[31m 紅色字\033[0m"
echo -e "\033[33m 黃色字\033[0m"
echo -e "\033[41;33m 紅底黃字\033[0m"
```

### 字背景顏色範圍:40<=>47

```
echo -e "\033[40;37m 黑底白字\033[0m"
echo -e "\033[41;37m 紅底白字\033[0m"
echo -e "\033[42;37m 綠底白字\033[0m"
echo -e "\033[43;37m 黃底白字\033[0m"
echo -e "\033[44;37m 藍底白字\033[0m"
echo -e "\033[45;37m 紫底白字\033[0m"
echo -e "\033[46;37m 天藍底白字\033[0m"
echo -e "\033[47;30m 白底黑字\033[0m"
```

> **最後面控制選項說明**
>
> \33\[0m 關閉所有屬性 \
> \33\[1m 設置高亮度 \
> \33\[4m 下劃線 \
> \33\[5m 閃爍 \
> \33\[7m 反顯 \
> \33\[8m 消隱 \
> \33\[30m -- \33\[37m 設置前景色 \
> \33\[40m -- \33\[47m 設置背景色 \
> \33\[nA 光標上移n行 \
> \33\[nB 光標下移n行 \
> \33\[nC 光標右移n行 \
> \33\[nD 光標左移n行 \
> \33\[y;xH設置光標位置 \
> \33\[2J 清屏 \
> \33\[K 清除從光標到行尾的內容 \
> \33\[s 保存光標位置 \
> \33\[u 恢復光標位置 \
> \33\[?25l 隱藏光標 \
> \33\[?25h 顯示光標&#x20;

```
echo -e "\033[41;33m 紅底黃字\033[5m hahah \033[0m"
```


---

# 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://kawsing.gitbook.io/opensystem/andoid-shou-ji/untitled-4/shell-script/hello-bash.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.
