You can set a KM variable from a shell script:
For more information, see the wiki Searching the Forum for Answers section.