Concatenation of spaces in Bash

The problem is simple.

for i in `seq $begin $progress_length` ; do progress_bar=$progress_bar'#' done for i in `seq $middle $end` ; do empty_space=$empty_space' ' done 

I need empty_space place the position after the execution line. I expected this to be the string x whitespaces. But finally, the line is empty. How to create a string x spaces?

+6
source share
3 answers

The problem may be that $empty_space has only spaces. Then, to display them, you must surround it with double quotes:

 echo "${empty_space}some_other_thing" 

You can try more interesting output with printf , for example, to get a few spaces. For example, to write 20 spaces:

 v=`printf '%20s' ' '` 
+7
source

Strings can be created by changing parameters. Substitution $ {str: offset: length} returns the substring str:

 space80=' ' hash80='################################################################################' progress_bar=${hash80:0:$progress_length-$begin+1} empty_space=${space80:0:$end-$middle+1} echo -n "$empty_space$progress_bar" 
+1
source

I understand your problem since I had exactly the same thing.

My solution was to concatenate the temporary character instead of a space, for example, , and then, at the end, replace all their occurrences with sed space:

 echo $myString | sed 's/☼/ /g' 

Hope this helps you!

0
source

Source: https://habr.com/ru/post/898870/


All Articles