当前位置:网站首页>There are spaces in the for loop variable in the shell -- IFS variable
There are spaces in the for loop variable in the shell -- IFS variable
2022-07-02 01:35:00 【Reef of】
- In the use of shell Of for loop , If there is a space in the middle of the string of the loop , Then the loop will be automatically divided , Here's the solution
Just change shell The separator is just
stay for Modify before loop IFS Variable , Example :
OLDIFS="$IFS" # Back up old IFS Variable
IFS=$'\n' # Change the separator to newline
for i in `cat aaa` #aaa The public key is stored in the file
do
echo "$i"
done
IFS="$OLDIFS" # Restore IFS Variable
- notes :
IFS Information about variables :
- Shell Put variables IFS Every character in is treated as a
Separator (delimeter), Use these characters as the terminator of each field for segmentation . - If IFS No settings , perhaps IFS The value of is set to
"\t\n"(space, tab and newline), Then all the at the beginning and end of the operation object space, tab and newline Sequences will be ignored , But in the middle of the operation object space, tab and newline The sequence will work as a delimiter . - If IFS It's not worth it
The default value is ( For example, in the program IFS It has been set ), Only in IFS White space characters in ( May be space, tab or newline One or more of ) Will be ignored at the beginning and end of the word , Here are words , Instead of the entire operation object . - IFS When more than one non white space character in the appears consecutively , Each non white space character is treated as a separate separator , But multiple consecutive white space characters are treated as a separator .
- If IFS It's empty (“null”), Word segmentation is not performed .
边栏推荐
- Leetcode, 3 repeatless longest subsequence
- The technology boss is ready, and the topic of position C is up to you
- 游戏思考15:全区全服和分区分服的思考
- 站在新的角度来看待产业互联网,并且去寻求产业互联网的正确方式和方法
- Four basic strategies for migrating cloud computing workloads
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- [IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
- NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
- [IVX junior engineer training course 10 papers to get certificates] 09 chat room production
- Fastadmin controls the length of fields in the table
猜你喜欢

企业应该选择无服务器计算吗?

卷積神經網絡(包含代碼與相應圖解)
![[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production](/img/b7/aecb815ca9545981563a1e16cfa19e.jpg)
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production

Day 13 of hcip (relevant contents of BGP agreement)

The technology boss is ready, and the topic of position C is up to you

人工智能在网络安全中的作用

Learning note 24 - multi sensor post fusion technology

Matlab uses audioread and sound to read and play WAV files

现货黄金分析的技巧有什么呢?

6-3漏洞利用-SSH环境搭建
随机推荐
LeetCode、3无重复最长子序列
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production
Basic usage of shell script
How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
[Maya] the error of importing Maya into Metahuman
Appium inspector can directly locate the WebView page. Does anyone know the principle
并发编程的三大核心问题
Three core problems of concurrent programming
[IVX junior engineer training course 10 papers] 06 database and services
Android high frequency network interview topic must know and be able to compare Android development environment
CEPH buffer yyds dry inventory
Circular statements in shell programming
浅浅了解Servlet
Raspberry pie 4B learning notes - IO communication (1-wire)
Matlab uses resample to complete resampling
I Brief introduction of radio energy transmission technology
Learning note 24 - multi sensor post fusion technology
Load and domcontentloaded in JS
Just using the way and method of consuming the Internet to land and practice the industrial Internet will not bring long-term development