bash - Variable substitution in script file and setting a new variable -


i'm attempting run command in shell script , set variable resulting process id. stripped down relevant parts, have:

#!/bin/bash user=myappuser path_to_app=/opt/folder/subfolder pid=`su - $user -c 'nohup $path_to_app/myapp --option > /dev/null 2>&1 & echo $!'`;   echo $pid 

i understand need use double quotes around nohup command variable substitution, if do, pid not being set. if use double quotes , hardcode path_to_app execute , set pid. i'm guessing it's problem combination of tick , single/double quotes.. i'm not sure solution is.

put command in double quotes $path_to_app substituted, , escape $ in $! included literally in argument su, , processed subshell.

pid=$(su - $user -c "nohup $path_to_app/myapp --option > /dev/null 2>&1 & echo \$!") echo $pid 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -