当前位置:网站首页>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 .
边栏推荐
- 现货黄金分析的技巧有什么呢?
- NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
- Datawhale community blackboard newspaper (issue 1)
- Hcip day 14 (MPLS protocol)
- How does schedulerx help users solve the problem of distributed task scheduling?
- 基于SSM实现微博系统
- Brief description of grafana of # yyds dry goods inventory # Prometheus
- What are the skills of spot gold analysis?
- Basic number theory -- Gauss elimination
- [rust web rokcet Series 2] connect the database and add, delete, modify and check curd
猜你喜欢
Should enterprises choose server free computing?
Develop those things: how to use go singleton mode to ensure the security of high concurrency of streaming media?
卷積神經網絡(包含代碼與相應圖解)
matlab 使用 audioread 、 sound 读取和播放 wav 文件
6-3 vulnerability exploitation SSH environment construction
Android high frequency network interview topic must know and be able to compare Android development environment
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码
Recommend an online interface mock tool usemock
Since I understand the idea of dynamic planning, I have opened the door to a new world
随机推荐
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production
Matlab uses audioread and sound to read and play WAV files
Android: how can golden nine and silver ten squeeze into the first-line big factories from small and medium-sized enterprises? The depth of interview questions in large factories
人工智能在网络安全中的作用
Circular statements in shell programming
Implementation of Weibo system based on SSM
Learning note 3 -- Key Technologies of high-precision map (Part 1)
Private project practice sharing [Yugong series] February 2022 U3D full stack class 009 unity object creation
TSINGSEE青犀平台如何实现同一节点同时播放多个视频?
成功实现边缘编码需要了解的六大经验教训
Since I understand the idea of dynamic planning, I have opened the door to a new world
k线图形态这样记(口诀篇)
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound
站在新的角度来看待产业互联网,并且去寻求产业互联网的正确方式和方法
Design and control of multi rotor aircraft (VII) -- sensor calibration and measurement model
CTF daily question day45 sensor
Game thinking 15: thinking about the whole region and sub region Services
城市选择器组件实现原理
电商系统中常见的9大坑,你踩过没?
Ubuntu20.04 PostgreSQL 14 installation configuration record