I have a question about my code. I'm writing a Bourne shell script that get a user list from server by who command then put it into a file then, it will check the name by read line and if the script found a duplicate name it will print out a warning msg with the username, otherwise it will print out that no duplication found. Everything working as it should when the script found the duplicate name, but when the script can not find any duplicate name it will not print anything, I know it is something to do with the last if statement but I try so many solutions but still stuck. If anyone have any suggestion please help me out. Really appreciated and answer in advance. ( see the code below )
#!/bin/sh
#who -u | sort -k1,5 > test3
log=~/Desktop/test3
while [ -f test ]; do
while IFS= read line; do
user=( $line )
if [ "$olduser" = "${user[0]}" ]; then
printf '\nThe user %s duplicated' "$olduser"
fi
olduser="${user[0]}"
done<"$log"
if [[ "$olduser" != "${user[0]}" ]]; then
printf '\nNo duplication found.\n';
fi
#Testing store value
#printf '\nolduser value = %s\n' "$olduser"
printf '\n=================================================================\n'
sleep 3
done
sh, only use code it understands. – dessert Oct 06 '17 at 06:25