11-20-2006
Andrek, I put in your code and it executed to work great! I went one step further and added the following piece to list out any existing directories and it's corresponding files:
if [ -d ${lsarry[$start]} ]
then
echo "-${lsarry[$start]}- is a directory"
cd ${lsarry[$start]}
ls -l
else
I do have one more question however. As someone always learning in the Unix Scripting field, I was wondering if you could explain what a few of the expressions are doing?
lslist="`ls -m | tr -d \",\"`"
set -A lsarry $lslist
start=1
while [ $start -lt ${#lsarry[*]} ] This is where I get confused. I understand that you are asking if the index is less than the value in the array, but what does the # before the lsarry mean? I take it that the[*] means the last array slot to contain a value?
do
if [ -d ${lsarry[$start]} ] I'm unfamiliar with -d before the array. Does this mean "IF 'D' = ArrayValue?" How is the code being interpreted?
then
echo "-${lsarry[$start]}- is a directory"
cd ${lsarry[$start]}
ls -l
else
echo "-${lsarry[$start]}- is not a directory"
fi
start=`expr $start + 1`
done
Everything after the first two questions in italics I understand, if you could explain those two just a little bit more, it would be greatly appreciated. Thanks!
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
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
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 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
As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies
5. Shell Programming and Scripting
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
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
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
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
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
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
LEARN ABOUT MOJAVE
cpanplus::shell::default::plugins::source
CPANPLUS::Shell::Default::Plugins::Source(3pm) Perl Programmers Reference Guide CPANPLUS::Shell::Default::Plugins::Source(3pm)
NAME
CPANPLUS::Shell::Default::Plugins::Source - read in CPANPLUS commands
SYNOPSIS
CPAN Terminal> /source /tmp/list_of_commands /tmp/more_commands
DESCRIPTION
This is a "CPANPLUS::Shell::Default" plugin that works just like your unix shells source(1) command; it reads in a file that has commands
in it to execute, and then executes them.
A sample file might look like this:
# first, update all the source files
x --update_source
# find all of my modules that are on the CPAN
# test them, and store the error log
a ^KANE$'
t *
p /home/kane/cpan-autotest/log
# and inform us we're good to go
! print "Autotest complete, log stored; please enter your commands!"
Note how empty lines, and lines starting with a '#' are being skipped in the execution.
BUG REPORTS
Please report bugs or other issues to <bug-cpanplus@rt.cpan.org<gt>.
AUTHOR
This module by Jos Boumans <kane@cpan.org>.
COPYRIGHT
The CPAN++ interface (of which this module is a part of) is copyright (c) 2001 - 2007, Jos Boumans <kane@cpan.org>. All rights reserved.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
SEE ALSO
CPANPLUS::Shell::Default, CPANPLUS::Shell, cpanp
perl v5.18.2 2014-01-06 CPANPLUS::Shell::Default::Plugins::Source(3pm)