如何在Korn Shell中重寫此腳本?它在Bash中是對的?我對所有炮彈之間的實際差異感到有點困惑......我是否正確地將它轉換爲Korn Shell?如何在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
快速測試和構造('if ... fi','$(...)'似乎在ksh中工作,您是否嘗試過? – Kevin
您是否嘗試將頂部的shebang行更改爲#!/ bin/ksh?我沒有看到任何明顯是bash特定的東西,它應該可以工作,或者用'set -vx',你應該可以在5分鐘內修復它。祝你好運。 – shellter