shell的输入和输出
1.echo ? ?echo [option] string
? ? ? ? ? ?-e 解析轉(zhuǎn)義字符
? ? ? ? ? ?-n 回車不換行,linux系統(tǒng)默認(rèn)回車換行
? ? ? ? ? ? 轉(zhuǎn)移字符 \c \t \f \n
#!/bin/bash
#echo
echo -e "this echo's 3 newlne\n\n\n"
echo "OK"
echo
echo "this is echo's 3 ewline\n\n\n"
echo "this log file have all beendone">mylogfile.txt
[test@szbirdora ~]$ sh echod.sh
this echo's 3 newlne
?
OK
this is echo's 3 ewline\n\n\n
上面可以看到有-e則可以解析轉(zhuǎn)移字符,沒有不能解析。echo空輸出為空
2.read 可以從鍵盤或文件的某一行文本中讀入信息,并將其賦給一個(gè)變量
read variable1 variable2
eg.
#!/bin/bash
#readname
echo -n "first name:"
read firstname
echo -n "last name:"
read lastname
echo "this name is $firstname $lastname"
| toto@toto-virtual-machine:~/c$ sh readname.sh first name:toto last name:toto this name is toto toto |
?
3.cat 顯示文件的內(nèi)容,創(chuàng)建內(nèi)容,還可以顯示控制字符
?cat [options]filename1 filename2
? ? -v ? 顯示控制字符(Windows文件)
?cat命令不會(huì)分頁顯示,要分頁可以采用more、less
4.管道|
5.tee 把輸出的一個(gè)副本輸送到標(biāo)準(zhǔn)輸出,另一個(gè)副本拷貝到相應(yīng)的文件中,一般與管道合用?tee [options] files
? ? ? ? ?-a 在文件中追加
eg.
[test@szbirdora 1]$ echo |tee myfile
[test@szbirdora 1]$ cat myfile
?
將myfile文件置空
6.文件重定向
command>filename ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ?---覆蓋輸出?
command>>filename ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ?---追加輸出
command>filename>&1 ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ---把標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯(cuò)誤重定向
command<<delimiter ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ---輸入直到delimiter分解符
command<filename ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ----輸入文件內(nèi)容到命令
command<- ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? --- 關(guān)閉標(biāo)準(zhǔn)輸入
>nullfile.txt ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ?---創(chuàng)建字節(jié)為0的文件
command1<filename>command3 ? ? ?? ? ? ? ---按從左到右順序執(zhí)行
eg.
說明:myfile為空間
[test@szbirdora 1]$ df -lh>myfile
[test@szbirdora 1]$ cat myfile
Filesystem ? ? ? ? ? ?SizeUsed Avail Use% Mounted on
/dev/sda1 ? ? ? ? ? ??20G 3.3G ? 16G 18% /
none ? ? ? ? ? ? ?? ?2.0G ? ? 0 2.0G ? 0% /dev/shm
/dev/sda2 ? ? ? ? ? ??79G ? 17G ? 59G 23% /u01
/dev/sda4 ? ? ? ? ? ??28G 3.9G ? 22G 15% /u02
[test@szbirdora 1]$ df -lh>myfile
[test@szbirdora 1]$ cat myfile
Filesystem ? ? ? ? ? ?SizeUsed Avail Use% Mounted on
/dev/sda1 ? ? ? ? ? ??20G 3.3G ? 16G 18% /
none ? ? ? ? ? ? ?? ?2.0G ? ? 0 2.0G ? 0% /dev/shm
/dev/sda2 ? ? ? ? ? ??79G ? 17G ? 59G 23% /u01
/dev/sda4 ? ? ? ? ? ??28G 3.9G ? 22G 15% /u02
[test@szbirdora 1]$ df -lh>>myfile
[test@szbirdora 1]$ cat myfile
Filesystem ? ? ? ? ? ?SizeUsed Avail Use% Mounted on
/dev/sda1 ? ? ? ? ? ??20G 3.3G ? 16G 18% /
none ? ? ? ? ? ? ?? ?2.0G ? ? 0 2.0G ? 0% /dev/shm
/dev/sda2 ? ? ? ? ? ??79G ? 17G ? 59G 23% /u01
/dev/sda4 ? ? ? ? ? ??28G 3.9G ? 22G 15% /u02
Filesystem ? ? ? ? ? ?SizeUsed Avail Use% Mounted on
/dev/sda1 ? ? ? ? ? ??20G 3.3G ? 16G 18% /
none ? ? ? ? ? ? ?? ?2.0G ? ? 0 2.0G ? 0% /dev/shm
/dev/sda2 ? ? ? ? ? ??79G ? 17G ? 59G 23% /u01
/dev/sda4 ? ? ? ? ? ??28G 3.9G ? 22G 15% /u02
[test@szbirdora 1]$ cat >>myfile<<exit
> China
> Hubei
> Suizhou
> exit
[test@szbirdora 1]$ cat myfile
China
Hubei
Suizhou
7.exec 可以用來替代當(dāng)前shell。現(xiàn)有任何環(huán)境變量都會(huì)清除
總結(jié)
以上是生活随笔為你收集整理的shell的输入和输出的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做事考虑后果,遵纪守法,会不会很痛苦?
- 下一篇: 4.录屏软件录屏端和接收端程序