我创建了这个脚本,我想在一行打印输出,我该怎么做? 这是我的剧本
#!/bin/bash
echo "enter start and stop numbers"
read start stop
while [ $start -lt $stop ]
do
echo $start
start=`expr $start + 1`
done
答案 0 :(得分:3)
使用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
答案 1 :(得分:1)
答案 2 :(得分:0)
for((i = 1; i <= 10; i ++)));做echo -n $ i;完成回声-e“ \ n”