Sponsored Content
Full Discussion: Array copy in ksh
Top Forums UNIX for Advanced & Expert Users Array copy in ksh Post 302401445 by PRKS on Saturday 6th of March 2010 06:24:34 AM
Old 03-06-2010
Hi fpmurphy,
I m using HP-UX.

All I want to do is to make a function that will store the list of files of a given directory (in an array perhaps) and return that array..

something like
Code:
listDir(){
...
...
return a; # a is an array
}

set -A arr1 $(listDir $dir1 $limit1)    #limit is the tail limit of ls -lrt
set -A arr2 $(listDir $dir2 $limit2)
set -A arr3 $(listDir $dir3 $limit3)

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

using array in ksh

hi all, need help with putting names in an array, i have a few servers which i look up by doing a 'find . -name "*.pid' and the format of the output is like following : ./servername/myserver.pid i was wondering how can i iterate through and store each name in one array my code is... (1 Reply)
Discussion started by: cesarNZ
1 Replies

2. Shell Programming and Scripting

how to copy one string in ksh into another

Hi Does anybody know if there is a utility/command in ksh which would allow to copy/insert the contents of one string into certain positions of the other? for example: A=" ABCDEF " B="HHH" I need to insert contents of string "B" into string "A" from position 3 to 5, so... (3 Replies)
Discussion started by: aoussenko
3 Replies

3. Shell Programming and Scripting

Ksh array solution.

I was wondering if ksh supported arrays. I have a script that may work with several hosts. I'd like a means of knowing how many hosts I'm working with and an easy way to access them (as variables) in a loop. I'm assuming there's some kind of foreach in shell scripting. (1 Reply)
Discussion started by: mrwatkin
1 Replies

4. UNIX for Dummies Questions & Answers

Need help with KSH Array assignment

The following command is only intermittently successful, depends on the data I give it: set -A ImageShifts_sorted `awk '/START_SECTION IMAGE_DEFINITION/ {getline;getline;getline;getline; print $2"-"$3}' temp.ASCII | sort -u` My Error: set: -1: unknown option Finally, If I run that... (3 Replies)
Discussion started by: nerdcurious
3 Replies

5. Shell Programming and Scripting

Array in ksh with if-else

Hi All, My Requirement is as follows: 1. User will input Source Sytem Code as input. 2. I have source system codes as 11, 34, 56, 99, 45 etc. OS Version: SunOS 5.8 Generic_117350-62 sun4u sparc SUNW,Sun-Fire-V890 My code is like... echo 'Source System Code: \c' read varSSCode... (3 Replies)
Discussion started by: saps19
3 Replies

6. UNIX and Linux Applications

Array in Ksh

Hi Guys, My code is something like this set -A A1 1 7 13 19 set -A A2 2 8 14 20 set -A A3 3 9 15 21 echo "Enter a number" read number for i in 0 2 3 4 do if }" ] then do something elif }" ] then do something elif }" ] then do something (4 Replies)
Discussion started by: jeanzibbin
4 Replies

7. Shell Programming and Scripting

[Solved] KSH: Array/If Help

RedHat 5 KSH I am creating an array, and then using case to go through and count for specific words. Then the count gets stored as an expression. string='ftp rcp rsh telnet ftp ftp' set -A myarray $string FTPCOUNT="0" for command in ${myarray} do case $command in ftp) FTPCOUNT=`expr... (2 Replies)
Discussion started by: nitrobass24
2 Replies

8. Shell Programming and Scripting

Array Count and Array Copy help

Hi all, I have the code as below " echo "File carried list after 1st loop "${fileStreamAssiagnInit}"" and I have the out put for the above code as below : Output : File carried list after 1st loop abcInd.csv sdgUS.csv sopSing.csv Here i want to count the number of elements in... (3 Replies)
Discussion started by: Balasankar
3 Replies

9. Shell Programming and Scripting

Assigning * as value in a ksh array

I want to extract each and single character from a password string and put it in an array. I tried this : set -A password "echo $passwd | awk '{for (i=1; i<=length($1); i++) printf "%s ",substr($1,i,1)}'` It's working as long that the password string doesn't contains any * I tried a few... (5 Replies)
Discussion started by: ce9888
5 Replies

10. Shell Programming and Scripting

Copy of array by index value fails

Hello, I have a complicated situational find and replace that I wrote in bash because I didn't know how to do everything in awk. The code works but is very slow, as expected. To create my modified file, I am looping through an array that was populated earlier and making some replacements at... (6 Replies)
Discussion started by: LMHmedchem
6 Replies
STR_SPLIT(3)								 1							      STR_SPLIT(3)

str_split - Convert a string to an array

SYNOPSIS
array str_split (string $string, [int $split_length = 1]) DESCRIPTION
Converts a string to an array. PARAMETERS
o $string - The input string. o $split_length - Maximum length of the chunk. RETURN VALUES
If the optional $split_length parameter is specified, the returned array will be broken down into chunks with each being $split_length in length, otherwise each chunk will be one character in length. FALSE is returned if $split_length is less than 1. If the $split_length length exceeds the length of $string, the entire string is returned as the first (and only) array element. EXAMPLES
Example #1 Example uses of str_split(3) <?php $str = "Hello Friend"; $arr1 = str_split($str); $arr2 = str_split($str, 3); print_r($arr1); print_r($arr2); ?> The above example will output: Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => F [7] => r [8] => i [9] => e [10] => n [11] => d ) Array ( [0] => Hel [1] => lo [2] => Fri [3] => end ) SEE ALSO
chunk_split(3), preg_split(3), explode(3), count_chars(3), str_word_count(3), for. PHP Documentation Group STR_SPLIT(3)
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy