Prev: is there a GNU Coreutils-like toolset for binary files?
Next: a=X; source <( echo a=Y ); echo $a
From: Mohsen on 29 Jan 2010 15:24 Hello All; A question from a new member: Does anybody has any comments to how I can have a 0 before "i" when it is less than 10? I want the code to create files like Ch01PH.inp ... Ch10PH.inp ... Ch20PH.inp. Thanks very much, Mohsen Here comes the code: #!/bin/ksh for i in {1..20} X=Ch$iPH.inp; done
From: Glenn Jackman on 29 Jan 2010 15:34 At 2010-01-29 03:24PM, "Mohsen" wrote: > Hello All; > > A question from a new member: > > Does anybody has any comments to how I can have a 0 before "i" when it > is less than 10? I want the code to create files like Ch01PH.inp ... > Ch10PH.inp ... Ch20PH.inp. > > Thanks very much, > Mohsen > > Here comes the code: > > #!/bin/ksh > > for i in {1..20} > X=Ch$iPH.inp; X=$(printf "Ch%02dPH.inp" $i) > done -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous
From: Seebs on 29 Jan 2010 15:36 On 2010-01-29, Mohsen <jafarikia(a)gmail.com> wrote: > Does anybody has any comments to how I can have a 0 before "i" when it > is less than 10? I want the code to create files like Ch01PH.inp ... > Ch10PH.inp ... Ch20PH.inp. printf "Ch%02dPH.inp\n" $i For extra fun: printf "Ch%02dPH.inp\n" {1..20} -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Stephane CHAZELAS on 29 Jan 2010 15:40 2010-01-29, 12:24(-08), Mohsen: > Hello All; > > A question from a new member: > > Does anybody has any comments to how I can have a 0 before "i" when it > is less than 10? I want the code to create files like Ch01PH.inp ... > Ch10PH.inp ... Ch20PH.inp. yes | head -n 20 | awk '{printf "Ch%02dPH.inp\n", ++n}' | xargs touch [...] > #!/bin/ksh > > for i in {1..20} > X=Ch$iPH.inp; > done Here you're writing a script that is specific to specific versions of specific implementations of a specific shell. Some implementations of ksh support {01..20}, some others {1..20%02d}. ksh is not standardized and the behavior varies from implementation to implementation (pdksh, mksh, zsh, AT&T ksh88, ksh93...) and version to version (ksh93r, ksh93s...). Your script above may work on your system today but may not work on other systems and may not even work on your systems a few weeks/years from now (unlikely though as your system's /bin/ksh implementation is likely to be the same and future versions of that implementation are likely to be backward compatible with older versions). -- St�phane
From: Gary Johnson on 29 Jan 2010 17:25 Mohsen <jafarikia(a)gmail.com> wrote: > Hello All; > > A question from a new member: > > Does anybody has any comments to how I can have a 0 before "i" when it > is less than 10? I want the code to create files like Ch01PH.inp ... > Ch10PH.inp ... Ch20PH.inp. > > Thanks very much, > Mohsen > > Here comes the code: > > #!/bin/ksh > > for i in {1..20} > X=Ch$iPH.inp; > done Since you're using ksh, add typeset -Z2 i before the loop. -- Gary Johnson
|
Pages: 1 Prev: is there a GNU Coreutils-like toolset for binary files? Next: a=X; source <( echo a=Y ); echo $a |