LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-25-2017, 02:05 PM   #1
anon3001
LQ Newbie
 
Registered: Jan 2016
Posts: 28

Rep: Reputation: Disabled
How do I make i skip by 2's in Unix?


Hi,

In linux, you can do something like:

for i in {1..100..2}; do echo "hi $i times"; done

and it will do this:

hi 1 times
hi 3 times
hi 5 times
etc...

I'm trying this in Solaris 10, but it will interpret {1..100..2} literally, like this:

hi {1..100..2} times

Any idea how I can get this working in Solaris 10? Thanks!
 
Old 10-25-2017, 02:35 PM   #2
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 757

Rep: Reputation: 145Reputation: 145
I don't have access to Solaris, but the seq command seems to be ubiquitous, so it's probably there.
Code:
for i in $(seq 1 2 100); do echo "hi $i times"; done
 
Old 10-25-2017, 02:45 PM   #3
anon3001
LQ Newbie
 
Registered: Jan 2016
Posts: 28

Original Poster
Rep: Reputation: Disabled
Thank you! Unfortunately, it doesn't look like this box has seq and I'm unable to install it. I'll keep check though
 
Old 10-25-2017, 02:52 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
It's a bash feature.
In Solaris /bin/bash is bash version 3 (but Solaris has no seq program!)
Test the expansion with echo
Code:
echo {1..100..2}
 
Old 10-25-2017, 02:57 PM   #5
anon3001
LQ Newbie
 
Registered: Jan 2016
Posts: 28

Original Poster
Rep: Reputation: Disabled
ok I got it. I just did:

for ((n=1;n<=10;n+=2)); do blah blah
 
  


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
How to make all Unix timestamps readable geokker Programming 2 10-02-2014 05:42 PM
How to make iconv to skip incorrect symbols or iconv alternative? x-stream Linux - Software 4 09-26-2011 09:32 PM
[SOLVED] KDE language packs - Can I make Portage skip over them (emerge kde-meta)? rrrssssss Gentoo 4 11-08-2009 02:45 PM
how can I make PCLinuxOS skip its setup questions? newbiesforever Linux - Distributions 8 07-08-2007 10:54 PM
How to make RSYNC skip a directory due to error message ArchW Linux - Networking 5 07-13-2006 10:26 AM

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

All times are GMT -5. The time now is 12:33 PM.

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