小编kpm*_*Dev的帖子

在 shell 脚本变量中存储空格

我需要在变量中存储特定数量的空格。

我试过这个:

i=0
result=""
space() {
    n=$1
    i=0
    while [[ "$i" != $n ]]
    do
        result="$result "
        ((i+=1))
    done
}

f="first"
s="last"
space 5

echo $f$result$s
Run Code Online (Sandbox Code Playgroud)

结果是“firstlast”,但我预计“first”和“last”之间有5个空格字符。

我怎样才能正确地做到这一点?

shell-script whitespace variable

5
推荐指数
1
解决办法
6965
查看次数

标签 统计

shell-script ×1

variable ×1

whitespace ×1