I'm writing a script that shuts down the Apache service, performs a function, and turns it back on.I'd like to get some type of interactive confirmation for each process. I'm not familiar with printf, but I believe it would be required for what I want to do.Here's a portion of the script below. As I turn off the service, I would like it to say what it will do, then report OK or NOT OK on the same line.ie.Shutting down Apache service:few seconds later...Shutting down Apache service: OK#!/bin/bash# Turn off Apacheecho Shutting down Apache service:'service apache2 stopif ( $(ps -ef | grep -v grep | grep apache2 | wc -l) > 0 )thenecho NOT OK!elseecho OK!fi
Interactive bash script
shell script;output
In bash, you can use the -n option of echo not to print the end of line.echo -n Shutting down Apache service:or, use printfprintf '%s' 'Shutting down Apache service'To include the newline in printf, put \n into the templateprintf '%s\n' 'NOT OK!'