首页 > 代码库 > Shell小程序

Shell小程序

1、保持顺序并消除重复行

#!/bin/bash

unset lines
while read line ; do
# echo ‘lines length: ‘${#lines[@]}

# echo ‘read:‘$line‘ ‘${#line}

if !(echo "${lines[@]}" | grep -w $line &>/dev/null); then
# echo ‘Not Found‘
lines=("${lines[@]}" $line)
fi
done

for line in ${lines[*]}
do
echo $line
done

Shell小程序