IFS usage in the "go" shell

Source: Internet
Author: User

http://blog.itpub.net/27181165/viewspace-775820/

An introduction to IFS
The Shell script has a variable called IFS (Internal field seprator), the internal domain delimiter. The full definition is the shell uses the value stored in IFS, which are the space, tab, and newline characters by default, to delimit words For the read and set commands, when parsing output from command substitution, and when performing variable substitution.
Shell environment variables are set, env two, where set variables can be imported into the env variable through the export tool. Where set is the display set shell variable, only valid in this shell; Env is a display set user environment variable, valid only in the current session. In other words, the SET variable contains the ENV variable, but the set variable is not necessarily an env variable. The difference between the two variables is that the scope of the variable is different. Obviously, the scope of the env variable is larger, and it can be used in Subshell.
IFS is a set variable that, when the shell handles "command substitution" and "parameter substitution", the shell, by default, is space, tab, newline, and then handles the special characters and, finally, re-assigns the variable to the value of IFS.
A simple example of two IFS
1 Viewing the value of IFS
echo "$IFS"

echo "$IFS" |od-b
0000000 040 011) 012 012
0000004
Direct output IFS is not see value, converted to binary can be seen, "040" is a space, "011" is the tab, "012" is the newline character "\ n". The last 012 is because echo defaults to wrap.
2 Applications in practice
#!/bin/bash
old_ifs= $IFS #保存原始值
Ifs= "" #改变IFS的值
...
...
ifs= $OLD _ifs #还原IFS的原始值

IFS usage in the "go" shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.