Shell
跳到导航
跳到搜索
简介
什么是 shell
什么是 shell 脚本
shell 环境
模式
交互模式
非交互模式
基本语法
解释器
注释
echo
echo 用于字符串的输出。
- 输出普通字符串:
echo "hello, world" # Output: hello, world
- 输出含变量的字符串:
name=xiaoming echo "hello, \"${name}\"" # Output: hello, "xiaoming"
- 输出含换行符的字符串:
# 输出含换行符的字符串 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:(当前目录路径)
printf
printf 用于格式化输出字符串。
printf 命令的语法:
printf format-string [arguments...]
参数说明:
- format-string: 为格式控制字符串
- arguments: 为参数列表。
默认,printf 不会像 echo 一样自动添加换行符,如果需要换行可以手动添加 \n
。