User Tools

Site Tools


action:Execute_a_Shell_Script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
action:Execute_a_Shell_Script [2019/10/07 16:15]
JMichaelTX Reorganize instructions for using shebang
action:Execute_a_Shell_Script [2019/11/25 16:53]
JMichaelTX
Line 33: Line 33:
 {{:​action:​km7-shell-script.png?​nolink|}} {{:​action:​km7-shell-script.png?​nolink|}}
  
-=== Python ===+==== Python ​====
  
 Accessing Keyboard Maestro Variables in Python is somewhat different. ​ Here is an example: Accessing Keyboard Maestro Variables in Python is somewhat different. ​ Here is an example:
Line 46: Line 46:
  
 Note that you can only read these environment variables. ​ You cannot write to them (or more accurately, you can write to them but that will not change the Keyboard Maestro variables that they were created from). Note that you can only read these environment variables. ​ You cannot write to them (or more accurately, you can write to them but that will not change the Keyboard Maestro variables that they were created from).
 +
 +==== awk ====
 +
 +[Using shell variables in awk](https://​stackoverflow.com/​a/​15787068/​915019) is also different than in most other shell languages. ​ You need to pass the environment variable as parameter to the -v flag.
 +
 +Some examples:
 +
 +```bash
 +# EXAMPLE 1
 +
 +echo | awk -v my_var=4 '​{print "My var is " my_var}'​
 +#-->My var is 4
 +
 +# EXAMPLE 2
 +
 +VAR=3
 +echo | awk -v env_var="​$VAR"​ '​{print "The value of VAR is " env_var}'​
 +#-->The value of VAR is 3
 +
 +# USING KM VARIABLES with awk
 +
 +echo | awk -v env_var="​$KMVAR_My_KM_Variable"​ '​{print "The value of My_KM_Variable is: \""​env_var"​\""​}'​
 +#-->The value of My_KM_Variable is: "Text from KM var"
 +```
 +
 +For a KM Macro that shows this, see:\\
 +**[MACRO: ​  Using KM Variables with Bash awk [Example]](https://​forum.keyboardmaestro.com/​t/​passing-argument-to-awk/​16169/​3)**
  
 ==== Passing Paths in Variables ==== ==== Passing Paths in Variables ====
action/Execute_a_Shell_Script.txt ยท Last modified: 2023/09/22 04:39 by peternlewis