tags:

views:

56

answers:

2

Hi, 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/3radicateRD";
        );
};
A: 

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')
Peter van der Heijden
Thanks for your fast response, this worked great.
Simmo
A: 

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/;//'
ghostdog74
Thanks for your fast response, iPhone doesn't have an awk binary so it didn't work in this case.
Simmo