tee
在屏幕上输出,同时也重定向到一个文件里。
-a 实现追加输出重定向的功能
[root@sc read]# echo "12ab" |tee t1.txt
12ab
[root@sc read]# echo "12ab" |tee t1.txt
12ab
[root@sc read]# cat t1.txt
12ab
[root@sc read]# echo "12ab" |tee -a t1.txt
12ab
[root@sc read]# cat t1.txt
12ab
12ab
printf
printf 是 Linux 中非常强大的命令,用于格式化和打印输出。它与 C 语言中的 printf 函数类似,但在命令行环境下使用。与 echo 命令相比,printf 提供了更强的格式控制能力。
[root@jack lianxi]# printf "hello world"
hello world[root@jack lianxi]# printf "hello world\n"
hello world
[root@jack lianxi]# printf "%d\n" "'a"
97
[root@jack lianxi]# printf "\x61\n"
a
echo
输出内容
-n 不换行
-e 让转义字符后面接的字符有特殊作用
\n 回车、换行
\t tab键
[root@sc read]# echo 123
123
[root@sc read]# echo -n 123
123[root@sc read]#
123[root@sc read]# echo "name\tsex\tage"
name\tsex\tage
[root@sc read]# echo -e "name\tsex\tage"
name sex age
脚本编写运算菜单
[root@sc read]# cat menu.sh
#!/bin/bash
echo "##########################"
echo "选择你需要的运算"
echo "1.加法"
echo "2.减法"
echo "3.乘法"
echo "4.除法"
echo "5.退出"
echo "##########################"
read -p "请输入你的选择[1/2/3/4/5]" option
echo "你的选择是 $option 运算"
[root@sc read]# bash menu.sh
##########################
选择你需要的运算
1.加法
2.减法
3.乘法
4.除法
5.退出
##########################
请输入你的选择[1/2/3/4/5]1
你的选择是 1 运算
[root@sc read]# bash menu.sh
##########################
选择你需要的运算
1.加法
2.减法
3.乘法
4.除法
5.退出
##########################
请输入你的选择[1/2/3/4/5]2
你的选择是 2 运算
seq
产生序列的一个命令
-w 等宽输出 width
-s 指定分隔符 separater
[root@sc read]# seq 5
1
2
3
4
5
[root@sc read]# seq 5 10
5
6
7
8
9
10
[root@sc read]# seq -w 5 10
05
06
07
08
09
10
[root@sc read]# seq -w -s ' ' 5 10
05 06 07 08 09 10
# 步长:默认的步长值为1,+2 表示每次都加2
[root@sc read]# seq 1 +2 10
1
3
5
7
9
[root@sc read]# seq 10 -1 1 # 从大到小,每次减1,步长为-1
10
9
8
7
6
5
4
3
2
1
seq 命令于 for循环结合
[root@sc read]# cat for.sh
#!/bin/bash
#使用seq产出的序列来空值for循环的次数
for i in $(seq 5)
do
echo $i
done
[root@sc read]# bash for.sh
1
2
3
4
5