Modify print() method to print on the same line The print method takes an extra parameter end=” “ to keep the pointer on the same line. The end parameter can take certain values such as a space or some sign in the double quotes to separate the elements printed in the same line.
To print multiple expressions to the same line, you can end the print statement in Python 2 with a comma ( , ). You can set the end argument to a whitespace character string to print to the same line in Python 3. With Python 3, you do have the added flexibility of changing the end argument to print on the same line.
To print on the same line in Python, add a second argument, end=' ', to the print() function call. print("It's me.")
If you want to print your text on the same line in Python 2, you should use a comma at the end of your print statement. Here's an example of this in action: print "Hello there!", print "It is a great day."
Use the -n
option to skip printing newline at the end. More reference at echo
docs.
So you could do something like this:
echo -n "$0: Starting backup process in '$backupdir'... "
use the more portable printf
:
printf "%s" "$0: Starting backup process in '$backupdir'... "
sleep 3
printf '[OK]\n'
echo -n hello
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With