IFS (Internal Domain Separator)

IFS (Internal Field Seprator), internal field separator

IFS is a kind of set variable. When the shell processes "command substitution" and "parameter substitution", the shell will disassemble and interpret the input variables according to the value of IFS, the default is space, tab, newline, and then process the special characters. Finally Regroup assignment to the variable.

Modify the default value of IFS, you can modify the division of the domain, the same effect as the F parameter in awk

#脚本
[dps@ccod131 bak]$ cat ifs.sh 
#!/bin/bash

IFS_OLD=$IFS
IFS='1'

i="abc1dfg1dcscdc" && echo $i
IFS=$IFS_OLD

#执行效果
[dps@ccod131 bak]$ bash ifs.sh 
abc dfg dcscdc

  • For the string "abc1dfg1dcscdc", using 1 split display, 3 parts can be displayed
[dps@ccod131 bak]$ echo "$IFS" | od -b
0000000 040 011 012 012
0000004

  • View the value of IFS, 040 space; 011 tab; 012 line break

Guess you like

Origin blog.csdn.net/jjt_zaj/article/details/113104899