Print 1 to 10 with space in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print 1 to 10 with space in shell script
# 8  
Old 11-28-2014
Hello Arup,

I have provided 4 solutions, could you please try following also and let us if it helps.

Code:
1- awk 'BEGIN{{ORS=" "} while(i<10){i++;print i}}'
 
2- echo 'for(i=1;i<=10;i++) i' | bc | paste -sd" " -

Thanks,
R. Singh
# 9  
Old 11-28-2014
Hi,

I have tried
Code:
#!/bin/sh

a=1
until [ $a -gt 10 ]
do
echo $a
a=`expr $a + 1`
done

But here output come as column. I want this in a single line as row with space.
# 10  
Old 11-28-2014
{1..10}
Two dots. I have corrected my previous post.
# 11  
Old 11-28-2014
Thanks Ravinder,

I dont want to use awk.

but 2nd one helps me..
# 12  
Old 11-28-2014
Code:
Last login: Fri Nov 28 07:52:28 on ttys000
AMIGA:barrywalker~> a=1; while [ $a -le 10 ]; do printf "$a "; a=$[ ( $a + 1 ) ]; done
1 2 3 4 5 6 7 8 9 10 AMIGA:barrywalker~> _

# 13  
Old 11-28-2014
This one let's you provide the limit on the command line...
Code:
#!/bin/bash

x=0
limit=$1
while [ $x -lt $limit ]
do
    x=$(( $x + 1 ))
    printf "%d " $x
done

Usage: test.sh <number>

Last edited by ongoto; 11-28-2014 at 04:51 AM..
# 14  
Old 11-28-2014
Thanks all for your reply..

I got my result by below
Code:
#!/bin/sh

a=1
until [ $a -gt 10 ]
do
echo "$a \c"
a=`expr $a + 1`
done

Now I want to replace 10 by n. and for n value 5 I want the output as
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

can any one help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to sum up the space allocated to filesystems

Hi , I Would like to know the space allocated by adding up all the allocated space to group of filesystems .. example , df -h|grep /db | awk '{ print $4 }' ---> giving me all the used space on the filesystem but need to know the total used space by adding up all the values (3 Replies)
Discussion started by: nsankineni
3 Replies

2. Shell Programming and Scripting

Shell Script to Abort if file name has space.

Hi, In my shell script I use the following code to copy files from one directory to other. for file in `ls`; do #----------------- Copy Files From INDIR to OUTDIR -------------# echoen "Copying File ${INDIR}/$file to ${OUTDIR}/${file}" cp ${INDIR}/$file ... (4 Replies)
Discussion started by: pinnacle
4 Replies

3. Shell Programming and Scripting

Help with Disk Space script in bash shell

Hi Guys, I'm a newb at shell scripting and successfully attempted a small disk space script (victory!!) but i'm wondering whether it actually takes into consideration KB,MB,GB. Please take a look at the script and advise. ##script to check if file sys has reached threshold. ... (3 Replies)
Discussion started by: Irishboy24
3 Replies

4. Shell Programming and Scripting

Space storage shell script issue!

Hi All, Linux 86x64bits Red Hat Linux O/S Could someone please check and let me know if the shell script has any syntax error as it's not sending mails Shell script: cat dataspace.sh #!/bin/bash export DBALIST="xyz@abc.com" export data_capacity df -k /oradata > dfk.result... (18 Replies)
Discussion started by: a1_win
18 Replies

5. Shell Programming and Scripting

Passing Parameter containing space in between to Shell Script

Hi, I have one shell script which use two parameter however one of its parameter have space in between. eg. a.sh 20110114 b c d here b c d is one parameter I used 'b c d' but its not giving correct result. Also i tried b\c\d but this one also didnt work. Any help would be... (5 Replies)
Discussion started by: diehard
5 Replies

6. Shell Programming and Scripting

Shell script for Server Mount Point space check

Does anybody have anything I can use to help me out with this one? (4 Replies)
Discussion started by: lbone007
4 Replies

7. Shell Programming and Scripting

Shell script partitions space monitor

Hello friends, I'm newbie in shell scripting... Until now i have this script: #!/bin/sh emailok = email1@domain.com emailissue = email2@domain.com limit="50" df -h | grep -vE '^Filesystem' | awk '{print $1 " " $4 " " $5}'|while read val do partition=$(echo $val | awk '{print... (9 Replies)
Discussion started by: john_doe
9 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

shell script to send email with usage of space in the directory as description :

shell script to send email with usage of space in the directory as description : Please any one help me in writing a script to send email with usage of space in the directory as description . (3 Replies)
Discussion started by: sakthifire
3 Replies

10. AIX

Creating a shell script to check filesystem space

I need to create a simple shell script to check filesystems space in a file system called "/arch_nb" then based on the percentage use either run another script or exit. I was thinking of something simple along the lines of: df -k | then some action to pipe for percentage used ...place... (10 Replies)
Discussion started by: heprox
10 Replies
Login or Register to Ask a Question