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
# 1  
Old 11-28-2014
Question Print 1 to 10 with space in shell script

Hi,

I want to print 1 to 10 or upto any number sequentially with space in a single line. Like,

1 2 3 4 5 6 7 ......

In shell script only.. Can anyone plz help me.

Thanks:
# 2  
Old 11-28-2014
Hello arup1980,

Following may help you in same.

Code:
i- seq -s" "  10
 
ii- awk 'BEGIN{{ORS=" "} while(i<10){i++;print i}}'
 
iii- 
cat check_count.ksh #### created a script named check_count.ksh, give proper permissions to it and execute it ###
for i in {1..10}
do
A=$A" "$i
done
echo $A

EDIT: one more solution as follows.

Code:
echo 'for(i=1;i<=10;i++) i' | bc | paste -sd" " -


Thanks,
R. Singh

Last edited by RavinderSingh13; 11-28-2014 at 02:27 AM.. Reason: Added a comment for 3rd solution
# 3  
Old 11-28-2014
Code:
for n in {1...10};do printf "$n ";done

or likewise
Code:
for n in $(seq 1 1 10);do printf "$n ";done

seq START INCREMENT END

Hope this helps
# 4  
Old 11-28-2014
Sorry Ravinder.. It doesn't work
# 5  
Old 11-28-2014
Code:
echo {1..10}


Last edited by MadeInGermany; 11-28-2014 at 03:24 AM.. Reason: two dots! Not three
# 6  
Old 11-28-2014
Hello arup,

Kindly let us know which solution didn't work also it is always good practice to give complete OS details which you are using along with
what you have tried so far to solve this problem.



Thanks,
R. Singh
# 7  
Old 11-28-2014
Hi Ravinder,
I am using unix shell, Bash shell.
you scripts are working in ksh n csh.

here say "seq command not found" also {1...10} doesn't work.

thanks for your 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