I am writing a installation script and would like to display the status of the script as it progresses.
example:
var1="pending"
var2="pending"
var3="pending"
print_status () {
echo "Status of Item 1 is: "$var1""
echo "Status of Item 2 is: "$var2""
echo "Status of Item 3 is: "$var3""
}
code that does something and then refreshes the
output above as the status of each variable changes.
To add multiple lines to a file with echo, use the -e option and separate each line with \n. When you use the -e option, it tells echo to evaluate backslash characters such as \n for new line. If you cat the file, you will realize that each entry is added on a new line immediately after the existing content.
First, the line containing the pattern /Linux/ is found. The command within the braces will run on the pattern found. {N;p} means read the next line and print the pattern space which now contains the current and the next line. Similarly, to print 2 lines, you can simply put: {N;N;p}.
So as far as I can tell, %% doesn't have any special meaning in a bash function name. It would be just like using XX instead. This is despite the definition of a name in the manpage: name A word consisting only of alphanumeric characters and under- scores, and beginning with an alphabetic character or an under- score.
Printing Newline in Bash The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “\n” is the conventional way. However, it's also possible to denote newlines using the “$” sign.
This code should give you the idea:
while :; do
echo "$RANDOM"
echo "$RANDOM"
echo "$RANDOM"
sleep 0.2
tput cuu1 # move cursor up by one line
tput el # clear the line
tput cuu1
tput el
tput cuu1
tput el
done
Use man tput
for more info. To see the list of capabilities use man terminfo
Look at this:
while true; do echo -ne "`date`\r"; done
and this:
declare arr=(
">...."
".>..."
"..>.."
"...>."
"....>"
)
for i in ${arr[@]}
do
echo -ne "${i}\r"
sleep 0.1
done
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