KMVAR not working at all in bash script (empty)

There have been several posts about KMVAR and bash, but none of them seems to apply to my problem: It seems I cannot use variables at all in a bash script. Please see the following small macro (which is just an excerpt of a more complex macro):

The file /tmp/xxx is indeed being created but it's empty which in turn means that the variable $KMVAR_usbpw is empty. It's not a problem with the keychain access, that works as a charm. If I write the variable usbpw to the clipboard:

it works nicely.

So why is the $KMVAR_usbpw not used or empty? Could it be related to anything in my environment (MacOS X 10.13.6, Homebrew, bash version of Homebrew used, ...)

As described in the Variables section of the manual:

Variables with names that start or end with “Password” or “PW” are considered passwords – their values will not be stored (except in memory) and they cannot be read directly by shell scripts or AppleScripts, though their consequences can easily be extracted, eg with the Set Clipboard to Text action, so you should clear them as soon as they have served their purpose. The Prompt For User Input dialog will display such variables in a password field.

The equivalent of your Execute Shell Script would be to use the Write to a File action to write the text %Variable%isbpw%. Alternatively, if you need to access it via the script you could also use stdin for the script, Execute Shell Script with input from text %Variable%isbpw%. Or not use a pw variable, although that has its own security issues.

Didn't dive that deep into the manual I must admit. Thanks, indeed that was the issue!

Few people do (and it wasn't my intention to “blame” you for not reading it, just to provide a link for future reference). There is really no way to know such things until they bite you like this or until you ask something like "how do I store a password and not have it written to disk?" and someone points you to this (or you go looking and happen to find it in the documentation).

Most things in Keyboard Maestro tend to be fairly discoverable, but sometimes there is extra power provided for more complex needs and sometimes that power comes at a cost like this.