ShellIFSreadLine. sh

Source: Internet
Author: User

ShellIFSreadLine. sh

processLine(){line="$@"echo $line} FILE="" if [ "$1" == "" ]; then    FILE="/dev/stdin"else    FILE="$1"     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<$FILEwhile read linedo    processLine $linedoneexec 0<&3 IFS=$BAKIFSexit 0

Use IFS for file analysis, or separate specific file 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 will only work in ksh,# and it will fail in bash IP=192.168.0.254IFS="."TMPIP=$(echo $IP)IFS=" "#spaceecho $TMPIP | read ip1 ip2 ip3 ip4INVIP=$ip4.$ip3.$ip2.$ip1echo $INVIP
We output the content of IFS, but some content cannot be directly displayed, but we can use some formatting to output the content:

 

 

echo $IFS | od -decho $IFS | od -becho $IFS | od -x
They are represented in different hexadecimal formats:

 



If it is caused by a colon (""), this variable does not need to be replaced by IFS !! So we can see the "original value" of this variable ". Otherwise, if no quotation marks are added, the output will be split Based on the IFS value and then merged into the output! $ * Is determined based on the first value in IFS! The two examples below are slightly different!

 

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.