Since the project was migrated from Aix to Redhat system, a previously written shell script did not run successfully, and after analysis, the key code was locked as follows:
readfilecontent () {Currentfile=$1fileshowrows=0filerealrows=0filebusinessdate=$2Filecountstarttime=0Filecountendtime=0 Echo$1 Echo$2 Cat$1| whileRead Line Do if["$fileRealRows"-eq"0" ] Then Echo "$line"fileshowrows=`Echo$line |awk '{split ($0,a, "|"); Print A[1]}'' Filecountstarttime=`Echo$line |awk '{split ($0,a, "|"); Print A[2]}'' Filecountendtime=`Echo$line |awk '{split ($0,a, "|"); Print A[3]}'` Echo "$fileShowRows" Echo "$fileCountStartTime" Echo "$fileCountEndTime" fi Echo 'filerealrows' "$fileRealRows"Let filerealrows+=1 Echo 'filerealrows' "$fileRealRows" Done Echo "$fileShowRows" Echo "$fileRealRows" Echo "$fileCountStartTime" Echo "$fileCountEndTime"}
This code is used to parse a piece of text
1| 20170322000001| 20170322235959 1| 00206342| 020602| 37906| 20170322| 083934| 21205967090| 21205967090| | | 10002930|
One piece of code that uses the difference is to read the contents of the file as a while pipeline, and the results are as follows in Aix and Linux systems:
Aix Execution Results:201703221|20170322000001|2017032223595912017032200000120170322235959filerealrows0filerealrows1filerealrows1filerealrows2122017032200000120170322235959
Linux execution results:201703221|20170322000001|2017032223595912017032200000120170322235959filerealrows0filerealrows1filerealrows1filerealrows20000
As you can see from the execution results, the parent variable assigned to Linux in the child shell is not valid for the parent shell, and the AIX system is valid. Here's how to modify it
readfilecontent () {Currentfile=$1fileshowrows=0filerealrows=0filebusinessdate=$2Filecountstarttime=0Filecountendtime=0 Echo$1 Echo$2 while Read Line Do if["$fileRealRows"-eq"0" ] Then Echo "$line"fileshowrows=`Echo$line |awk '{split ($0,a, "|"); Print A[1]}'' Filecountstarttime=`Echo$line |awk '{split ($0,a, "|"); Print A[2]}'' Filecountendtime=`Echo$line |awk '{split ($0,a, "|"); Print A[3]}'` Echo "$fileShowRows" Echo "$fileCountStartTime" Echo "$fileCountEndTime" fi Echo 'filerealrows' "$fileRealRows"Let filerealrows+=1 Echo 'filerealrows' "$fileRealRows" Done <$1 Echo "$fileShowRows" Echo "$fileRealRows" Echo "$fileCountStartTime" Echo "$fileCountEndTime"}
of a while pipeline in a Linux system.