Reputation: 55
I'm new to bash, and need some simple script. It runs jar, and has to find "RESPONSE CODE:XXX". I need this response code (just XXX). I've try this:
URL=$1
echo $URL
callResult=`java -jar RESTCaller.jar $URL`
status=$?
if [ $status -eq 0 ]; then
result=`$callResult >> grep 'RESPONSE CODE' | cut -d':' -f 2`
else
echo error
fi
I get ./run.sh: line 7: RESPONSE: command not found
What am I doing wrong?
Upvotes: 2
Views: 4242
Reputation: 8587
URL=$1
echo $URL
callResult=`java -jar RESTCaller.jar $URL`
status=$?
if [ $status -eq 0 ]; then
result=$($callResult 2>&1 grep 'RESPONSE CODE' | cut -d':' -f 2)
else
echo error
fi
You were piping result to some invalid file name >> means write into file adding on..
2>&1 means redirect stderr to stdin - which is all of its output -
Upvotes: 1
Reputation: 19333
In this line:
result=`$callResult >> grep 'RESPONSE CODE' | cut -d':' -f 2`
You should be piping output to grep, not redirecting. Change it to this:
result=`$callResult | grep 'RESPONSE CODE' | cut -d':' -f 2`
Also, the syntax is a bit off, and you're better off avoiding backticks when possible. This is even better:
result="$(echo ${callResult} | grep 'RESPONSE CODE' | cut -d':' -f 2)"
Upvotes: 2