-1

There is a Bash command ./supload.sh -u USERNAME -k PASSWORD -r dest_dir/ src_dir, which sends parameters: USERNAME, PASSWORD, destionation_directory, source_directory to "supload.sh" and uploads files. During upload, this command returns answers (see screenshot) and when it finishs upload, it gives final answer:

[*] All files uploaded

How can I get the last answer of the command into varialbe?

Something like this

./supload.sh -u USERNAME -k PASSWORD -r dest_dir/ src_dir

# get command answers' last string into variable

I need this answer to be sure that all files uploaded successfully and then do some actions. Thanks in advance.

  • The only thing you need beyond that answer about syntax is to pipe your output to `tail` or `sed` or `awk` or something to only return the last line (assuming you only care about that last line and don't mind not seeing the previous output). If you do need to see the output as well then you need to pipe it to `tee` or similar and/or store the whole thing in the variable and then use `tail`/etc. to get the last line from the variable. – Etan Reisner Jul 31 '15 at 15:07

1 Answers1

0

Assuming all the answers are 1 per line you could do

answer=$(./supload.sh -u USERNAME -k PASSWORD -r dest_dir/ src_dir | tail -1)
Eric Renouf
  • 13,950
  • 3
  • 45
  • 67