glu*_*uke 1 string bash whitespace substitution
为了进行字符串匹配,我需要使用前导空格定义bash变量。我需要从整数开始定义它,例如:
jj=5
Run Code Online (Sandbox Code Playgroud)
在我看来,printf是个好主意,因此,如果我想填充最多6个字符的空格:
jpat=`printf " %6i" $jj`
Run Code Online (Sandbox Code Playgroud)
但不幸的是,当我尝试调用该变量时:
echo $jpat
Run Code Online (Sandbox Code Playgroud)
前导空格被删除,我只得到$jj原样的整数。
有什么办法可以保留这样的空间?
(这等效于:v=' val'; echo $v$v。为什么输出中没有开头和多个空格?)