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!
3
  • 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. Commented Jul 12, 2014 at 2:10
  • >>can edit the legacy script #no# Commented Jul 12, 2014 at 2: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?" Commented Jul 12, 2014 at 3:16

1 Answer 1

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:
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.