bash Unix 打印循环输出在一行上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8938471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unix print loop outputs on one line
提问by user1160199
I created this script and I want to print the outputs on one line, how do I do this? This is my script
我创建了这个脚本,我想在一行上打印输出,我该怎么做?这是我的脚本
#!/bin/bash
echo "enter start and stop numbers"
read start stop
while [ $start -lt $stop ]
do
echo $start
start=`expr $start + 1`
done
采纳答案by jaypal singh
Using printfor echo -n. Also, try to use start=$(($start + 1))or start=$[$start + 1]instead of back ticks to increment the variable.
使用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
回答by John
回答by raghvendra gupta
for ((i=1;i<=10;i++)); do echo -n $i; done; echo -e "\n"
对于 ((i=1;i<=10;i++)); 做 echo -n $i; 完毕; 回声 -e "\n"

