Sponsored Content
Top Forums Shell Programming and Scripting Unix Korn Shell Array Issue (SunOS) Post 302096936 by Janus on Monday 20th of November 2006 06:57:34 PM
Old 11-20-2006
Unix Korn Shell Array Issue (SunOS)

Hello,

I'm currently messing around with arrays for the first time in scripting (Unix Korn Shell). All I'm trying to do right now before I make things complicated is read through and print out to screen whether the read file is or is not a directory.

Here is my directory:

ls -l
total 16
-rwxrwxrwx 1 xrjbn3y staff 354 Nov 20 18:29 echodir
-rw-r--r-- 1 xrjbn3y staff 136 Apr 5 2006 local.cshrc
-rw-r--r-- 1 xrjbn3y staff 136 Apr 5 2006 local.cshrc.JASS.20050613104129
-rw-r--r-- 1 xrjbn3y staff 167 Apr 5 2006 local.login
-rw-r--r-- 1 xrjbn3y staff 157 Apr 5 2006 local.login.JASS.20050613104129
-rw-r--r-- 1 xrjbn3y staff 184 Apr 5 2006 local.profile
-rw-r--r-- 1 xrjbn3y staff 174 Apr 5 2006 local.profile.JASS.20050613104129
drwxr-x--- 2 xrjbn3y root 512 Nov 8 18:40 scripts

Here is my script:
#!/bin/ksh
##########
i=0
max=`ls -l . | wc -l`
set -A keiths `ls -l . | grep -v total | awk '{print $9}'`
set -A filelist `ls -l . | grep -v total | awk '{print $1}' | cut -c1`

while [ $i -le $max ]
do
print ${keiths[$i]}
if [ ${filelist[$i]} = "d" ] then
print ${filelist[$i]}
else
print 'Not A Directory'
fi
(( i=i+1 ))
done

Here are my results:
./echodir
echodir
Not A Directory
local.cshrc
Not A Directory
local.cshrc.JASS.20050613104129
Not A Directory
local.login
Not A Directory
local.login.JASS.20050613104129
Not A Directory
local.profile
Not A Directory
local.profile.JASS.20050613104129
d
scripts
./echodir[11]: test: argument expected
Not A Directory

./echodir[11]: test: argument expected
Not A Directory

./echodir[11]: test: argument expected
Not A Directory


I bolded within my script what the errors at the bottom of the result are not liking. With this being my first time using arrays, I'm not sure what needs to be corrected within the test to make sure the conditions are ok. If everything within the syntax is ok, is the script executing 3 more times for some reason? Any insight you guys can provide would be greatly appreciated.

Thanks,
Ryan
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Oracle To Korn Shell Array

I'm attempting to populate an array in ksh using the following command: set -A $(SELECT_INVOICE | sed '/^$/d') SELECT_INVOICE is a function that executes the SQL query. Problem: Some of the invoice numbers have alpha characters with spaces(example: OVEN MICRO). The Korn shell is treating... (1 Reply)
Discussion started by: kdst
1 Replies

2. Shell Programming and Scripting

korn shell array?

I read it is possible to provide values for an array with the -A option to the read statement; however, I have not been able to get this to work. When I execute a script with the -A option to the read statement, the shell complains that it is an illegal option. If this works, can someone provide... (5 Replies)
Discussion started by: cstovall
5 Replies

3. Shell Programming and Scripting

I can't decalar an array in my korn shell script

I have a script that contains #!/usr/bin/ksh set -A X 'hallo' 'world' echo ${X} echo ${X} when I execute it I get an errror message sh ./test.ksh ./test.ksh: -A: bad option(s) but if I do this at the command prompt I am able to create it set -A myarray '1' '2' '3' echo ${myarray}... (4 Replies)
Discussion started by: zilla30066
4 Replies

4. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

5. Shell Programming and Scripting

korn shell .kshrc in sunos

Hi, My login shell is c shell I have a line in .cshrc like setenv a 1000 I have a line in .profile like ENV=$HOME/.kshrc export ENV and in my .kshrc a=10 export a I wrote one korn script #!/bin/ksh echo $a (3 Replies)
Discussion started by: shahnazurs
3 Replies

6. Shell Programming and Scripting

need help with korn shell array

I have a korn shell script that reads a file with just one column in the file. If the file has more than 5 entries it is split using split -5. This means that is we have 15 entries I will end up with 3 files with 5 entries/lines in each and if I have 23 entries I will end up with 5 files with the... (2 Replies)
Discussion started by: kieranfoley
2 Replies

7. Shell Programming and Scripting

Generate array name at run time Korn shell

Hi, I am trying to define number of array based on constant derived during execution phase of a script. Here is what i am trying.. #First Part, Get LUN input from User lun_count=4 count=0 set -A my_lun while : do while ]; do read L?"Enter Lun "$count" Number:" ... (2 Replies)
Discussion started by: harris2107
2 Replies

8. Shell Programming and Scripting

Korn Shell Array maximum value less than other value

I have a text file with several key words that I am trying to isolate. I have grepped for the unknowns in the text file, but each unknown has a corresponding location. I have created an array that holds all the unknowns and another array that holds all of the locations and compares them based on... (12 Replies)
Discussion started by: ther2000
12 Replies

9. Shell Programming and Scripting

'*' vs. '@' in Korn Shell Array Variables

In order to use the shellcurses functions described at: Shell Curses function library I am learning about ksh, which has arrays. My trusty Kochan & Wood book says that for any Korn Shell array AR : ${AR } expands to all the defined array elements, and ${#AR } expands to the number... (3 Replies)
Discussion started by: Clovis_Sangrail
3 Replies

10. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies
DH_USRLOCAL(1)							     Debhelper							    DH_USRLOCAL(1)

NAME
dh_usrlocal - migrate usr/local directories to maintainer scripts SYNOPSIS
dh_usrlocal [debhelperoptions] [-n] DESCRIPTION
dh_usrlocal is a debhelper program that can be used for building packages that will provide a subdirectory in /usr/local when installed. It finds subdirectories of usr/local in the package build directory, and removes them, replacing them with maintainer script snippets (unless -n is used) to create the directories at install time, and remove them when the package is removed, in a manner compliant with Debian policy. These snippets are inserted into the maintainer scripts by dh_installdeb. See dh_installdeb(1) for an explanation of debhelper maintainer script snippets. When the Rules-Requires-Root field is not (effectively) binary-targets, the directories in /usr/local will have ownership root:staff and the mode will be 02775. These values have been chosen to comply with the recommendations of the Debian policy for directories in /usr/local. When Rules-Requires-Root has an effective value of binary-targets, the owners, groups and permissions will be preserved with one exception. If the directory is owned by root:root, then ownership will be reset to root:staff and mode will be reset to 02775. This is useful, since that is the group and mode policy recommends for directories in /usr/local. OPTIONS
-n, --no-scripts Do not modify postinst/prerm scripts. NOTES
Note that this command is not idempotent. dh_prep(1) should be called between invocations of this command. Otherwise, it may cause multiple instances of the same text to be added to maintainer scripts. CONFORMS TO
Debian policy, version 2.2 SEE ALSO
debhelper(7) This program is a part of debhelper. AUTHOR
Andrew Stribblehill <ads@debian.org> 11.1.6ubuntu2 2018-05-10 DH_USRLOCAL(1)
All times are GMT -4. The time now is 08:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy