Get hash value using bash
I need to get the PID value out of a variable(containing hash data) using BASH. eval errors because of the array inside of it. This script is on an iPhone.
eval "$(launchctl list com.3radicateRD)"
eval: line 10: syntax error near unexpected token `('
eval: line 10: ` "ProgramArguments" = ('
------------------------------------------------------
{
"Label" = "com.3radicateRD";
"LimitLoadToSessionType" = "System";
"OnDemand" = false;
"LastExitStatus" = 0;
"PID" = 6810;
"TimeOut" = 30;
"ProgramArguments" = (
"bash";
"/var/mobile/Library/3radicateRD/3rad开发者_高级运维icateRD";
);
};
I do not know bash on IPhone (or launchctl for that matter). But normally you would need to get the line containing "PID" = ...
, remove quotes, semicolons, spaces and tabs from that and pass that result to eval
. You can do that using grep
and sed
:
eval $(launchctl list com.3radicateRD | grep '"PID"' | sed 's/["; \t]//g')
No need to use eval. Just execute your program normally.
launchctl list com.3radicateRD | awk '/PID/{print $3}'
Update: I don't have iphone, so i am guess there is bash?
launchctl list com.3radicateRD | while read line
do
case "$line" in
*PID* )
set -- $line
echo $3
esac
done
And if you have sed,
launchctl list com.3radicateRD | sed '/PID/s/.*= //;s/;//'
精彩评论