I'm trying to set an export that would effectively kill a process based on the PID that pgrep feeds it. Running the command kill $(pgrep myAppName) appears to work (if 'myAppName' were the name of an actual running process)... But how would you save this command as an exported environment variable? Every variation of the command that I could think of seems to try and evaluate pgrep myAppName into something like 20137 (or a similar PID value), and running the exported variable works the first time, but obviously won't work after that since the exported command is actually kill 20137, where that process has already been terminated.How can I get this to be properly saved in a variable, so I can just type something like $KILL_APPNAME to kill that process, every single time the command is run?
Exporting a piped command without evaluating output?
shell;environment variables;kill
What I think you're trying to do needs eval in order to work:THING=eval kill \$(pgrep myAppName)$THINGbut it's awkward and doesn't work by default in all shells (for example it doesn't work by default in zsh although an option can be set to make it work). Whatever you are trying to do is most likely better solved with something cleaner and easier like a function:kill_my_app() {    kill $(pgrep myAppName)}kill_my_appOr, as others have pointed out in comments, just use pkill or killall which does exactly what you need.