linux-tutorial/codes/shell/基本脚本/echo示例.sh
2019-10-29 18:22:19 +08:00

42 lines
658 B
Bash

#!/usr/bin/env bash
# 输出普通字符串
echo "hello, world"
# Output: hello, world
# 输出含变量的字符串
echo "hello, \"zp\""
# Output: hello, "zp"
# 输出含变量的字符串
name=zp
echo "hello, \"${name}\""
# Output: hello, "zp"
# 输出含换行符的字符串
echo "YES\nNO"
# Output: YES\nNO
echo -e "YES\nNO" # -e 开启转义
# Output:
# YES
# NO
# 输出含不换行符的字符串
echo "YES"
echo "NO"
# Output:
# YES
# NO
echo -e "YES\c" # -e 开启转义 \c 不换行
echo "NO"
# Output:
# YESNO
# 输出内容定向至文件
echo "test" > test.txt
# 输出执行结果
echo `pwd`
# Output:(当前目录路径)