awktutorial/11-user-def-functions.awk

28 lines
598 B
Awk
Executable File

#!/usr/bin/awk -f
# https://www.grymoire.com/Unix/Awk.html
# user defined functions
# very simple, functions are defined like this:
# function fname(arg) { do something }
# the function can be defined anywhere in the script, even at the
# end after all the BEGIN and END blocks, because awk reads the
# whole script before executing it.
BEGIN {
print "Enter a word:"
getline word < "-"
if (word == "") {
print "You're no fun."
} else {
repeatit(word)
}
}
function repeatit(w) {
print "You typed \"" w "\"."
print "Again, that was \"" w "\"."
}