Reputation: 43
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
Upvotes: 4
Views: 16319
Reputation: 77085
Using printf
or echo -n
. Also, try to use start=$(($start + 1))
or start=$[$start + 1]
instead of back ticks to increment the variable.
#!/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
Upvotes: 4