Bash中的空白连接

cie*_*bor 6 bash whitespace concatenation

问题很简单.

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
Run Code Online (Sandbox Code Playgroud)

我需要empty_space在进度条之后定位内容.我预计它将是x空格的字符串.但最后字符串是空的.我怎样才能创建x空格字符串?

Die*_*lla 8

问题可能是因为$empty_space只有空格.然后,要输出它们,你必须用双引号括起来:

echo "${empty_space}some_other_thing"
Run Code Online (Sandbox Code Playgroud)

您可以尝试更有趣的输出,printf例如获取多个空格.例如,要写20个空格:

v=`printf '%20s' ' '`
Run Code Online (Sandbox Code Playgroud)