请教一个shell问题?
linux版本:[root@localhost aw]# uname -a
Linux localhost.localdomain 3.10.0-1160.25.1.el7.x86_64 #1 SMP Wed Apr 28 21:49:45 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
用作测试的目录下的文件
[root@localhost aw]# ls -lS --time-style=long-iso
总用量 24
-rwxr-xr-x 1 root root 286 2021-06-10 15:56 remove.sh
-rw-r--r-- 1 root root 9 2021-06-10 15:55 arg1
-rw-r--r-- 1 root root 9 2021-06-10 15:55 arg2
-rw-r--r-- 1 root root 9 2021-06-10 15:55 arg3
-rw-r--r-- 1 root root 9 2021-06-10 15:56 arg4
-rw-r--r-- 1 root root 9 2021-06-10 16:29 arg5
代码一
#!/bin/bash
ls -lS --time-style=long-iso | awk 'BEGIN {
getline; getline;
name1=$8; size=$5
}
{
name2=$8;
if (size==$5)
{
"md5sum "name1 | getline; csum1=$1;
"md5sum "name2 | getline; csum2=$1;
if ( csum1==csum2 ) { print name1; print name2 }
};
size=$5; name1=name2;
}'
输出结果:
[root@localhost aw]# ./remove.sh
arg1
arg2
arg3
arg4
代码二
#!/bin/bash
ls -lS --time-style=long-iso | awk 'BEGIN {
getline; getline;
name1=$8; size=$5
}
{
name2=$8;
if (size==$5)
{ print name1; print name2 };
size=$5; name1=name2;
}'
输出结果:
[root@localhost aw]# ./remove1.sh
arg1
arg2
arg2
arg3
arg3
arg4
arg4
arg5
请问代码一与代码二输出的结果为何不同?