Reputation: 99
I'm running JAVA code inside shell script
java -cp ojdbc6.jar:. javaClassName args
Is it possible to do command substitution for java output inside shell
Output of java code is an array:
[{ID:143},{Name:John},{Age:32},{Designation:Enginner},{City:Delhi},{Phone:+123 456 789},{Email:[email protected]}]
I want to declare above array as variables inside the same shell-script where java code runs
ID=${ID}
Name=${Name}
Upvotes: 0
Views: 84
Reputation: 2705
Try
grep -oE '(:[^}]+)' | head -2 | tr -d ':'
Demo :
$read -r Id Name <<<$(echo '[{ID:143},{Name:John},{Age:32},{Designation:Enginner},{City:Delhi},{Phone:+123 456 789},{Email:[email protected]}]' | grep -oE '(:[^}]+)' | head -2 | tr -d ':' )
$echo $Id
143
$echo $Name
John
$
Upvotes: 2