How do I rewrite this script in Korn Shell? It’s in Bash right? I’m a little confused to the actual differences between all the shells… Am I on the right track to converting it to Korn Shell?
usage ()
{
echo "usage: ./file.sk user"
}
# test if we have two arguments on the command line
if [[ $# != 1 ]]
then
usage
exit
fi
# Search for user
fullname=$(cut -f1 -d: /etc/passwd | grep "$1")
if [[ $? -eq 0 ]]; then
echo "User already found:"
grep $1 /etc/passwd
exit
else
#get numbers
cat /etc/passwd | gawk -F: '{print $3}' | sort -n > currentuid4
#get last number
last=`tail -1 currentuid4`
echo last $last
#add +1
newuid=`expr $last + 1`
#print it
echo "ADDED: $1 with UID: $newuid"
exit
fi
I suggest replacing
[[…]]by[…]and using-eq/-neto make the script more portable on different shells.