1

I have this legacy delete script script, It is doing some delete work on a remote application. When processing of delete is done it will return #completed successfully# or it will return

#
    *nothing more to delete*
    *Program will exit*
#

I would like to assign its output and execute the delete script as long its output is "completed successfully".

I am unable to assign the results of the script to a variable. I am running the shell script from folder X while the delete script is in folder Y. Besides the script below, I also tried:

response=$(cd $path_to_del;./delete.sh ...)

I am unable to make this work.

#!/bin/bash
path_to_del=/apps/Utilities/unix/
response='completed successfully'

counter=1
while [[ $response == *successfully*  ]]
do
         response= working on batch number: $counter ...
         echo $response
         (cd $path_to_del;./delete.sh   "-physicalDelete=true") > $response

         echo response $response
         ((counter++))
done

echo deleting Done!
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
  • 1
    Feels like something is getting lost in tranlation. Can you re-format the script and fix the obvious bugs like `response= working on batch $counter ...`? Then run `bash -x yourscript` and post output as to what exactly isn't working? Also if you can edit the legacy script, it would make more sense to me to give the script exit codes. – Reinstate Monica Please Jul 12 '14 at 02:10
  • >>can edit the legacy script #no# – JavaSheriff Jul 12 '14 at 02:24
  • legacy script might be writing those results to `stderr`, in which case see [answer to "Bash how do you capture stderr to a variable?"](http://stackoverflow.com/a/11087523/319698) – npostavs Jul 12 '14 at 03:16

1 Answers1

2

general ways to pass output from a subshell to the higher level shell is like this:

 variable="$(command in subshell)"

or

read -t variable < <(command)

therefore the modifications to your script could look like:

response="$(cd $path_to_del;./delete.sh   "-physicalDelete=true")"

or

cd $path_to_del
response="$(./delete.sh   "-physicalDelete=true")"

this line will fail and needs fixing:

response= working on batch number:
Deleted User
  • 2,551
  • 1
  • 11
  • 18