1

I have a script that takes about 10 mins to run. I want to print something to the terminal to give a visual indicator that something is happening. The original command is as follows:

stats:
        $(MAKE) add > last_output.txt 2> err.txt

It waits for the Makefile target "add" to return and sends the output to last_output.txt and then doesn't print out the errors to the terminal.

I don't have much experience with Makefiles and shell scripting but, after googling I have come up with a line like this:

stats:
        @until $(MAKE) $* > last_output.txt 2> err.txt; do echo -n "." ; done

It doesn't print anything out. But what I want to happen is while the original script is waiting to return the output look like:

$ make stats
.
..
...
....
.....
<results of target "stats">

I can't add a progress bar to the original script because I cannot edit it. Since I can't add a progress bar I figured something like this would still do a similar job. Any help is greatly appreciated.

1 Answers1

2

The until command doesn't work like that. Instead it runs a command repeatedly until it returns a succesful status.

I.e. until is a command repeater, not a "wait for completion" expression.

However if you are willing to use an external tool, then with something like pv you could print progress updates as long as there is output from the make command.

$(MAKE) add 2> err.txt | pv -t -p -i 0.1 -w 40 > last_output.txt

This will print a small left-right animating bar with a ticking timer like so:

0:00:08 [    <=>                       ]

You can test it on the command line yourself with something like this:

while true; do date; sleep 0.1; done | pv -t -p -i 0.1 -w 40 > /dev/null

If you want a more bash-oriented solution, you can try to look at this question with perhaps some answers that would fit your requirements:
Using Bash to display a progress indicator

Casper
  • 33,403
  • 4
  • 84
  • 79
  • Reminder that GNU Make default shell is `sh`, not `bash`, for anyone going for the linked Bash alternative. – Andreas Apr 17 '22 at 14:07
  • @Casper, That sounds like a fantastic idea! Unfortunately, I don't have permission on the system to install packages. In regards to the Bash progress indicators, since I am calling the command from a Makefile I'm not sure how to merge a Makefile and Bash. – Runtime Error Apr 17 '22 at 15:45