Shell IFS readline.sh

Source: Internet
Author: User
Tags readline

Processline () {line= "[email protected]" echo $line} file= "" if ["] = = =" "]; Then    file= "/dev/stdin" Else    file= "$"     if [!-f $FILE]; then        echo "$FILE: does not exists"        exit 1
   
    elif [!-R $FILE]; Then        Echo ' $FILE: Can not read '        exit 2    Fifi bakifs= $IFSIPS =$ (echo-en "NB") exec 3<&0exec 0< $FILEWH Ile Read Linedo    processline $linedoneexec 0<&3 ifs= $BAKIFSexit 0
   





Use IFS for file analysis, or to split file-specific characters

#shell Environment $IFS useage# s:internal Field separatorifs=:a=hello:worldecho $a #OutPut is Hello world #IFS Save Key Value, maybe space\tab\ ' \ n ' \other token#sparse input or output key value  # The following code segment would only work In ksh,# and it'll fail in bash ip=192.168.0.254ifs= "." tmpip=$ (Echo $IP) ifs= "" #spaceecho $TMPIP | Read Ip1 ip2 ip3 ip4invip= $ip 4. $ip 3. $ip 2. $ip 1echo $INVIP
We output the IFS content, but since some of the content is not directly visible, we can use some formatting to output the content:

echo $IFS | Od-decho $IFS | Od-becho $IFS | Od-x
each is represented by a different binary:



If it is caused by a colon (""), it means that the variable is not replaced with IFS!! So you can see the "original value" of this variable. Conversely, if you do not quote, the output will be based on the value of IFS to split after the combined output! $* is determined by the first value in the IFS! Here are two examples with subtle differences!






Shell IFS readline.sh

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.