DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 11th March 2012
aleunix aleunix is offline
Real Name: Alessandro
Spam Deminer
 
Join Date: May 2008
Location: Italy
Posts: 224
Thanked 3 Times in 3 Posts
Default Script: how translate for i in `seq $1 $2`?

How translate the bash command:
for i in `seq $1 $2`

on:
$ echo $SHELL
/bin/ksh

?

Essentially i would like pass two argument on for instead to put two fix number all the time.

Now i have problem with seq (bash).
Reply With Quote
  #2   (View Single Post)  
Old 11th March 2012
denta denta is offline
Fdisk Soldier
 
Join Date: Nov 2009
Posts: 73
Thanked 0 Times in 0 Posts
Default

man jot
Reply With Quote
  #3   (View Single Post)  
Old 11th March 2012
aleunix aleunix is offline
Real Name: Alessandro
Spam Deminer
 
Join Date: May 2008
Location: Italy
Posts: 224
Thanked 3 Times in 3 Posts
Default

Thanks.

Code:
#!/bin/sh
for i in `jot - $2 $3 1`
do
echo $i
done

Last edited by aleunix; 11th March 2012 at 04:18 PM.
Reply With Quote
  #4   (View Single Post)  
Old 12th March 2012
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 572
Thanked 14 Times in 13 Posts
Default

Glad the problem is solved with jot. Just to clarify ...

Is seq really a bash command now? I don't find it mentioned in the bash man pages I looked at (though they're not the very latest). Both NetBSD and some Linux distributions have a stand-alone seq(1) command. And bash has a construct (in newer versions anyway)

% echo {1..10}
1 2 3 4 5 6 7 8 9 10

which does a similar thing (in simple cases).
Reply With Quote
  #5   (View Single Post)  
Old 12th March 2012
aleunix aleunix is offline
Real Name: Alessandro
Spam Deminer
 
Join Date: May 2008
Location: Italy
Posts: 224
Thanked 3 Times in 3 Posts
Default

Now i'm on OpenBSD so i don't check it but i think you have right.

Now i was thinking at something sufficient general for avoid to use seq or jot that can be work on OpenBSD and Linux without modification of the code.
These attempt failed:
Quote:
for i in {$1.. $2}
for ((i=$1; i <= $2 ; i++))
so, in the end, now i'm using that approach:
i=$1
while [ "$i" -le $2 ]
do
echo $i
let "i+=1"
done
I haven't check on Linux but given that i make this change while see it:
Example 11-17. C-style syntax in a while loop from the Advanced Bash-Scripting Guide
i suppose that should work.
Reply With Quote
  #6   (View Single Post)  
Old 12th March 2012
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 572
Thanked 14 Times in 13 Posts
Default

Quote:
Originally Posted by aleunix View Post
These attempt failed:
for i in {$1.. $2}
{ .. } is a bash-ism not found in ksh.

Quote:
for ((i=$1; i <= $2 ; i++))
The (( )) should contain an arithmetic expression, rather than a command list.


Quote:
now i'm using that approach:
i=$1
while [ "$i" -le $2 ]
do
echo $i
let "i+=1"
done
I haven't check on Linux ...
I checked and it works.
Reply With Quote
Reply

Tags
bash, command for, ksh, script, shell

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NAT64: OpenBSD 5.1 will translate between IPv4 and IPv6 J65nko News 0 27th February 2012 10:37 PM
Crontab won't run script Petrocelli08 FreeBSD General 4 7th March 2009 04:19 AM
Handy X11 script Gabe_G23 Guides 6 25th October 2008 05:08 PM
my 1st sh script graudeejs Programming 12 18th August 2008 10:25 PM
Shell Script. bsdnewbie999 Programming 21 15th July 2008 07:54 AM


All times are GMT. The time now is 04:51 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick