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
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
for ((i=1;i<=10;i++)); do echo -n $i; done; echo -e "\n"