LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 04: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, 06:19 PM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850Reputation: 850
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, 04:01 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Or simpler still:
Code:
printf "%d\n" {10..1}
 
1 members found this post helpful.
Old 12-05-2012, 01: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, 02:05 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
VIM syntax highlighting: Use of AWK syntax inside shell scripts kaiserkarl13 Programming 0 11-13-2012 11:04 AM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 01:52 PM
Starting httpd: httpd: Syntax error on line 209 of /etc/httpd/conf/httpd.conf: Syntax sethukpathi Linux - Networking 6 04-12-2008 12:26 PM
Help with syntax dr3vi1 Linux - Newbie 7 08-09-2005 11:20 AM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 07:09 PM


All times are GMT -5. The time now is 02:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration