3 ms·
"That’s how Kernigham and Ritchie did it in 1978. Nowadays they just haul in the software weenies with their fancy objects and methods." No, we use getopts(3C).
by Annatar 9y ago
"That’s how Kernigham and Ritchie did it in 1978. Nowadays they just haul in the software weenies with their fancy objects and methods."
No, we use getopts(3C). For decades now. I even use getopts in my shell programs. For old UNIX hands, using getopts in C or in shell programming is certainly nothing new. How, you ask? Simple! Watch this:
while getopts hDd: Option
do
case "$Option"
in
h)
Usage
;;
D)
Debug=true
;;
d)
Destination="$OPTARG"
;;
esac
done
shift `expr $OPTIND - 1` # I did not use $((OPTIND - 1)) for a reason!
Bam! Your program will now behave exactly as every other UNIX executable, especially if you do not name it with .sh postfix and make it executable, the user won't be able to tell the difference between it or say, ls(1)!
Having said that, the example in the article cements what I've been saying all along: C is more than fine in the programming hands of a thoughtful mind.