[20210930]IFS= read -r line.txt
[20210930]IFS= read -r line.txt
--//放假前看了一下如標題的寫法,不知道這個-r的主要作用.從網上抄的例子驗證看看.
$ echo " a b c " | { IFS= read -r line; echo "[$line]" ; }
[ a b c ]
$ echo " a b c " | { read -r line; echo "[$line]" ; }
[a b c]
--//很容易混淆,實際上IFS=,臨時取消IFS設定,IFS預設空格,tab,回車三個字元.
--//在IFS=的情況下,read -r 可以保持前面的空格.
$ echo -n "$IFS" |xxd -c 16 -g 1
0000000: 20 09 0a
$ echo " a b c " | { IFS= read -r line; echo "[$line]" ; }
[ a b c ]
$ echo " a b c " | { read -r line; echo "[$line]" ; }
[a b c]
$ echo " a b c " | { read line; echo "[$line]" ; }
[a b c]
--//可以發現對於中間的空格無效.當然-r還有獨特作用.例子:
$ echo " a b\t c " | { IFS= read line; echo "[$line]" ; }| xxd -c 16 -g 1
0000000: 5b 20 20 20 20 61 20 62 74 20 63 20 20 20 5d 0a [ a bt c ].
--//有點不理解直接刪除\.
$ echo " a b\t c " | { IFS= read -r line; echo "[$line]" ; }| xxd -c 16 -g 1
0000000: 5b 20 20 20 20 61 20 62 5c 74 20 63 20 20 20 5d [ a b\t c ]
0000010: 0a
--//-r 保持\不解析.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2794819/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- requests庫中r.content 與 r.read() 的使用方式
- Shell中的IFS
- [20190312]bash IFS例子.txt
- [20210930]bbed恢復刪除的資料.txt
- direct path read/read temp等待事件事件
- [20210930]bbed讀取資料塊7 fffext.sh.txt
- READ ME
- Read a story
- 等待事件db file sequential read、db file scattered read和direct read的區別事件
- [Bash] read command
- TIC Read Status
- Read-onlydynamicdata
- MySQL的repeatable readMySql
- Preferred Read Failure GroupsAI
- [LeetCode] 158. Read N Characters Given Read4 II – Call multipleLeetCode
- [Javascript] How javascript read the property?JavaScript
- Spark Streaming Failed to read checSparkAI
- zend_std_read_property
- 【Linux shell】while read lineLinuxWhile
- Oracle:db file scattered readOracle
- Cannot read property ‘aDataSort‘ of undefinedUndefined
- [!] Attempt to read non existent folder `***********`
- read by other session等待事件Session事件
- read content in a text file in pythonPython
- MXNet: wait_to_read 方法AI
- IFS:英國近10%高校或因疫情影響面臨破產風險
- mysql snapshot read快照讀及current read當前讀與鎖lock之一MySql
- mysql中read commited與repeatable read兩種隔離級別的測試MySqlMIT
- Linux read命令的基本使用!Linux
- Cross-Origin Read Blocking (CORB)ROSBloCORB
- Handler_read_*的總結
- read by other session 等待事件分析Session事件
- 【等待事件】db file sequential read事件
- 【等待事件】db file scattered read事件
- db file scattered read等待事件事件
- db file sequential read等待事件事件
- Shell程式設計-read命令程式設計
- 【r