How to use `Variable` in shell script

I read How to Use Execute Shell Script -- With Input From - #9 by CJK and How Do I Pass a KM Variable to the Execute Shell Script Action? - #5 by JMichaelTX

and still confused

I have this macro:

I don't think I can do cd "$MYPATH" to get the variable though

Yes you are mixing things up.

You are using execute shell script with input from.
In that variant the value of MYPATH is STDIN for you script. Try like this:

If you run this you will get the output ~/Library.

If you want to use it as a variable you have to extend it with 'KMVAR_'.

See for example this:

you will get the output KMVAR_MYPATH=~/Library

2 Likes

@fap has got you covered, but you should also take a look at the "Execute a Shell Script" action's wiki page, particularly the section "Using Keyboard Maestro Variables".

2 Likes