LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-03-2012, 03:53 PM   #1
learngeek
LQ Newbie
 
Registered: Dec 2012
Posts: 4

Rep: Reputation: Disabled
syntax to use 10 9 8 7 6 5 4 3 2 1 blastoff?


#!/bin/bash
n=1
while [ $n -le 10 ];
do
echo $n
let n++
done

I was not able to get it to reverse with a blastoff

How do I code it?
 
Old 12-03-2012, 05:19 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello learngeek, welcome to LQ,
Code:
#!/bin/bash
n=10
while [ $n -ge 1 ];
do 
        echo $n
        let n--
done
Markus
 
Old 12-04-2012, 03:01 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or simply
Code:
#!/bin/bash
for n in {10..1}
do
  echo $n
done
 
Old 12-04-2012, 11:20 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Or simpler still:
Code:
printf "%d\n" {10..1}
 
1 members found this post helpful.
Old 12-05-2012, 12:42 PM   #5
learngeek
LQ Newbie
 
Registered: Dec 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you markush. I tried the first one. It was easier for me.

One more question I need help with.

How do I write bash to set up the following like this

1 3 2 4 3 5 4 6...100.

I need to write that looks like

1234
3456 and so on.

Thank you
 
Old 12-05-2012, 01:05 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
My I suggest looking into an 'if' statement that checks what number you are up to and simply place a newline after the appropriate entry.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] VIM syntax highlighting: Use of AWK syntax inside shell scripts kaiserkarl13 Programming 1 03-03-2021 09:59 AM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
Starting httpd: httpd: Syntax error on line 209 of /etc/httpd/conf/httpd.conf: Syntax sethukpathi Linux - Networking 6 04-12-2008 11:26 AM
Help with syntax dr3vi1 Linux - Newbie 7 08-09-2005 10:20 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration