I've written a quick-and-dirty script to time some reports from a web service:
BASE_URL='http://example.com/json/webservice/'
FIRST=1
FINAL=10000
for report_code in $(seq 1 $FINAL); do
(time -p response=$(curl --write-out %{http_code} --silent -O ${BASE_URL}/${report_code}) ) 2> ${report_code}.time
echo $response # <------- this is out of scope! How do I fix that?
if [[ $response = '404' ]]; then
echo "Deleting report # ${report_code}!"
rm ${report_code}
else
echo "${report_code} seems to be good!"
fi
done
I need to wrap the time
command in a subshell so I can redirect its output, but that makes the value of $response
unavailable to the parent shell. How do I get around this problem?
{ … }
instead of a subshell( … )
. – Gilles 'SO- stop being evil' Dec 28 '16 at 17:51