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 Both sides next revision
action:Execute_a_Shell_Script [2019/04/25 05:11]
peternlewis UTF-8 and Non-ASCII Characters
action:Execute_a_Shell_Script [2019/05/03 13:13]
JMichaelTX ADD example of Bash quoting
Line 47: Line 47:
 ``` ```
  
-This must be a full path.  ​**If the path starts with a tilde (~)**, then you must first convert it to a full path using the [[action:​Filter | Filter, Expand tilde (~) paths]] Action BEFORE the Execute Shell Script Action.+**Consider These Guidelines**
  
-For more info, see an excellent, detailed discussion of [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​29| How To Quote Paths by @ccstone]].+  * This must be a full path.  **If the path starts with a tilde (~)**, then you must first convert it to a full path using the [[action:​Filter | Filter, Expand tilde (~) paths]] Action BEFORE the Execute Shell Script Action. 
 +  * Like all Bash variables, the Keyboard Maestro Variable must _not_ be between single quotes (`'`) in order for the variable to be expanded to / replaced by its value. ​ So, for example, **this will _not_ work**: 
 + 
 +```bash 
 +# 🚫 Does NOT Work 
 +/​usr/​local/​bin/​emacsclient -e '​(w3m-browse-url "​$KMVAR_SafariURL"​)'​ 
 +``` 
 +because although the Variable is between double-quotes,​ it is in a string that is between single-quotes. 
 + 
 +  * So, to handle this case, you can use something like this: 
 + 
 +```bash 
 +# ✅ This WORKS 
 +/​usr/​local/​bin/​emacsclient -e '​(w3m-browse-url "'"​$KMVAR_SafariURL"'"​)'​ 
 +``` 
 +One key Bash feature that makes this work is that when two quoted strings are adjacent, they will be concatenated. ​ So after the Variable is expanded, the command string might look like this: 
 + 
 +```bash 
 +/​usr/​local/​bin/​emacsclient -e '​(w3m-browse-url "​https://​www.apple.com"​)'​ 
 +``` 
 + 
 +For more info, see these discussions in the Keyboard Maestro Forum: 
 +  * [[https://​forum.keyboardmaestro.com/​t/​png-metadata-comment/​6375/​29| How To Quote Paths by @ccstone]]. 
 +  * [[https://​forum.keyboardmaestro.com/​t/​trouble-expanding-variable-in-shell-script/​13664/​2?​u=jmichaeltx | Trouble Expanding Variable in Shell Script by @PeterNLewis]] 
 + 
 +---
  
 ==== UTF-8 and Non-ASCII Characters ==== ==== UTF-8 and Non-ASCII Characters ====
action/Execute_a_Shell_Script.txt · Last modified: 2023/09/22 04:39 by peternlewis