4
我创建了这个脚本,我想在一行上打印输出,我该怎么做? 这是我的脚本在一行上的Unix打印循环输出
#!/bin/bash
echo "enter start and stop numbers"
read start stop
while [ $start -lt $stop ]
do
echo $start
start=`expr $start + 1`
done
我创建了这个脚本,我想在一行上打印输出,我该怎么做? 这是我的脚本在一行上的Unix打印循环输出
#!/bin/bash
echo "enter start and stop numbers"
read start stop
while [ $start -lt $stop ]
do
echo $start
start=`expr $start + 1`
done
使用printf
或echo -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