shell 编程 (6)echo read -e \n \c 重定向
echo str1.显示普通字符串echo "str"可不带""双引号可转义\"str\"eg:[root@k8s-master test2]# echo strstr[root@k8s-master test2]# echo "str"str[root@k8s-master test2]# echo \"str\""str"[root@k8s-master...
·
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. 显示命令执行结果
反引号``
更多推荐
已为社区贡献12条内容
所有评论(0)