|
||||
ksh arrays
i have started to use (better said learn) ksh as a scripting language about a week ago. as i was reading "Learning the Korn Shell (2nd edition)" i have reached at some point the array part.
so i have tried to make the following simple script. Code:
# cat array.sh #!/usr/local/bin/ksh93 K=~/bin cd $K KA=$(ls $PRE.*) print ${#KA[*]} Code:
# ./array.sh 1 Using the -x feature of ksh i have the following output: Code:
# ksh93 -x array.sh + ls addvpn.sh disk.size.sh ksh.sh s.test.sh array.sh vpn.sh + KA=$'addvpn.sh\ndisk.size.sh\nksh.sh\ns.test.sh\nssh.connect.sh\nvpn.sh' + print 1 Code:
... print ${KA[1]} Code:
# ksh93 -x array.sh + ls addvpn.sh disk.size.sh ksh.sh s.test.sh ssh.connect.sh vpn.sh + KA=$'addvpn.sh\ndisk.size.sh\nksh.sh\ns.test.sh\nssh.connect.sh\nvpn.sh' + print '' all the best, v |
|
|||
I really have to question why you're writing a script for KSH and not using a more popular shell such as bourne or BASH ?
Ignoring that .... Maybe this will clear some things up: Code:
$ set -A someArray `ls *.jpg` $ echo ${somearray[*]} blah.jpg something.jpg file.jpg aa.jpg $echo ${somearray[0]} blah.jpg If you're going to use a variable to store the contents of the output of an application you need to put it in these backquotes ` ` |
|
||||
That doesn't work either. I was using $() for command substitution because i found that this is the proper way to do it in ksh (from the man page and book i mentioned).
I am using ksh because i found out from a bsdforums post that people are using ksh for scripting because it has much more features when it comes to scripting. Ok i don't know if this is the wisest decision so i am gonna ask your opinion about which shell do you use for scripting? thank you all the best, v |
|
|||
Quote:
http://www.opengroup.org/onlinepubs/...xcu/chap2.html |
|
|||
Quote:
|
|
|||
Hello,
Quote:
Many do use Korn for scripting now, I think it is number 2 or 3 after Bash - but Bash is still the undisputed king (cf. LinuxQuestions 2007 Member Choice Awards). Like corey_james said, for ultimate portability, go with Bourne. But, learning Korn is still a good skill to have, and if you know Korn or Bash, you know about 90% of the other respective language.
__________________
And the WORD was made flesh, and dwelt among us. (John 1:14) |
|
||||
thanks for your opinion JMJ_coder. every new thing doesn't harm to be learned. that was the first thought when i started ksh. anyway i think i'll go with bourne because of the portability. one more question. do you guys recommend some book for bourne?
thank you all the best, v |
|
||||
http://www.amazon.com/Unix-Shell-Pro...0078008&sr=8-2
Also, the Sam's Teach Yourself Shell Scripting in 24 Hours isn't bad. |
|
|||
Hello,
The book I have is Kochan & Wood's Unix Shell Programming And it covers both Bourne and Korn! The Unix in a Nutshell also has a good section on each of the Bourne, Korn, and the C shells.
__________________
And the WORD was made flesh, and dwelt among us. (John 1:14) |
|
||||
Small detail, people on bsdforums suggesting to use ksh most probably are openbsd persons using the default user's shell ksh which is really the public domain ksh, not ksh93 (c) AT&T.
There are several variants of ksh, most of all compatible with /bin/sh, always with subtle differences.
__________________
da more I know I know I know nuttin' |
|
||||
HI.
The article http://en.wikipedia.org/wiki/Compari...omputer_shells has an extensive table for viewing the similarities and differences of the features of many shells (8 *nix shells + cmd.exe) ... cheers, drl |
Tags |
ksh |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Basic Perl arrays question | stukov | Programming | 12 | 18th November 2008 08:44 PM |
How to vectorize a function for numpy arrays in Python | kasse | Programming | 0 | 26th August 2008 12:12 PM |
C 2D arrays | jgroch | Programming | 16 | 2nd August 2008 01:54 AM |