Unix打印循环输出在一行上

时间:2012-01-20 08:17:21

标签: bash unix

我创建了这个脚本,我想在一行打印输出,我该怎么做? 这是我的剧本

#!/bin/bash

echo "enter start and stop numbers"

read start stop

while [ $start -lt $stop ]

do

echo $start

start=`expr $start + 1`

done

3 个答案:

答案 0 :(得分:3)

使用printfecho -n。此外,尝试使用start=$(($start + 1))start=$[$start + 1]而不是后退标记来增加变量。

#!/bin/bash

echo "enter start and stop numbers"
read start stop
while [ $start -lt $stop ]
do
    printf "%d " $start
    start=$(($start + 1))
done

#!/bin/bash

echo "enter start and stop numbers"
read start stop
while [ $start -lt $stop ]
do
    echo -n "$start "  # Space will ensure output has one space between them
    start=$[$start + 1]
done

答案 1 :(得分:1)

使用

echo -n $start

退房: http://ss64.com/bash/echo.html

答案 2 :(得分:0)

for((i = 1; i <= 10; i ++)));做echo -n $ i;完成回声-e“ \ n”

相关问题