echo str
1. 顯示普通字符串
echo "str"
可不帶""
雙引號可轉義\"str\"
eg:
[root@k8s-master test2]# echo str
str
[root@k8s-master test2]# echo "str"
str
[root@k8s-master test2]# echo \"str\"
"str"
[root@k8s-master test2]# echo "\"str\""
"str"
[root@k8s-master test2]#
2. read
從標準輸入中讀取一行,把輸入行中整個字段的值賦給shell變量
eg:
[root@k8s-master test2]# sh t0.sh
a b c
a b c is input arg
[root@k8s-master test2]# cat t0.sh
#!/bin/bash
read in_arg
echo "$in_arg is input arg"
[root@k8s-master test2]#
3. -e
開啓轉義
\n 換行
\c 不換行
eg:
[root@k8s-master test2]# echo -e "hello\nworld"
hello
world
[root@k8s-master test2]# echo "hello\nworld"
hello\nworld
[root@k8s-master test2]#
[root@k8s-master test2]# ./t1.sh
hello! world
[root@k8s-master test2]# cat t1.sh
#!/bin/bash
echo -e "hello! \c"
echo "world"
[root@k8s-master test2]#
4. 定向至文件
echo只能一行,cat 結合eof能多行
[root@k8s-master test2]# echo "hello world" > hello.txt
[root@k8s-master test2]# cat hello.txt
hello world
[root@k8s-master test2]#
[root@k8s-master test2]# cat world.txt
[root@k8s-master test2]# cat > world.txt <<EOF
abc
def
EOF
[root@k8s-master test2]# cat ./world.txt
abc
def
[root@k8s-master test2]# cat <<EOF >world1.txt
> abc
> def
> hello
> EOF
[root@k8s-master test2]# cat ./world1.txt
abc
def
hello
[root@k8s-master test2]#
5. 原樣輸出
單引號
6. 顯示命令執行結果
反引號``