[Solved] KSH: Array/If Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] KSH: Array/If Help
# 1  
Old 08-28-2012
[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.

Code:
string='ftp rcp rsh telnet ftp ftp'
set -A myarray $string
FTPCOUNT="0"
for command in ${myarray[*]}
do
case $command in
ftp) FTPCOUNT=`expr $FTPCOUNT +1` ;;
rcp) RCPCOUNT=`expr $RCPCOUNT +1` ;;
esac
done
if (($FTPCOUNT !=0) || ($RCPCOUNT !=0)); then
echo "It works"
fi

So i do all of this, but my "if $FTPCOUNT !=0; then" part fails
dash_bin_ksh: 3: not found

I can echo $FTPCOUNT and get "3" which is correct.

Can someone point me in the right direction?
# 2  
Old 08-28-2012
Does this work in your ksh?
Code:
if (( (FTPCOUNT!=0) || (RCPCOUNT!=0) ))

If not, try:
Code:
if [ $FTPCOUNT -ne 0 -o $RCPCOUNT -ne 0 ]

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 08-28-2012
Thats perfect...thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Need help understanding ksh scripting.

Can any one please tell me where the error in below script. Output is not as per my requirement. if condition not comparing the result of record count of a file with 1. where is the pbm in my script? Appreciate your help.. #!/bin/ksh #Module- #Summary- To move the file to direcotries if... (9 Replies)
Discussion started by: shivadanam
9 Replies

2. Shell Programming and Scripting

[Solved] Array for parameters from 5th position

Hi All, I am writing a script where the first 5 parameters are mandatory but the script should be able to handle a maximum of 9 parameters (with the remainig 4 optional) I would like to load all parameters from 5th parameter positioninto an array. the piece of code I am writing for this:... (0 Replies)
Discussion started by: snailrider
0 Replies

3. Solaris

[Solved] Issues connecting to storage array

I have two T2000 servers connected to sun storage array StorEdge 3310 as follows: CH0 connected to SNGL BUS CONF CH1 connected to HOST1 CH2 open CH3 connected to HOST2 DUAL BUS CONF open I have created some luns which I can mount and use on HOST1 but from HOST2 I cant see them ... (3 Replies)
Discussion started by: aliyesami
3 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Reading Array And Send An Email

I am trying to find an example for reading an array instead of reading a file and send out an email in ksh. Can you please help is that possible? Algorithm #!/bin/ksh i=0 set -A ARR if then let i=$ ARR="A does n't match with B" fi if then let i=$ ARR="P does n't match with Q"... (11 Replies)
Discussion started by: Ariean
11 Replies

5. UNIX for Dummies Questions & Answers

[Solved] ksh script - can't figure out what's wrong

Hi! (I guess this could of gone into the scripting forum, but Unix for Dummies seemed more appropriate. Please note that I am not in school, so Homework doesn't seem appropriate either. You guys can let me know if you think otherwise.) I am following an exercise in a book on ksh scripting which... (2 Replies)
Discussion started by: sudon't
2 Replies

6. Homework & Coursework Questions

[SOLVED] blowfish algorithm: encrypting the p-array.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to encrypt the p-array. The first element will print correctly once returned from my encrypt... (2 Replies)
Discussion started by: robin_simple
2 Replies

7. Programming

[solved]help passing array of structs to function in c

this is my code to try and prinnt out a deck of cards. the print function worked when used inside main without being a function but now i cant get it to work as a function probably since i dont know how to pass a struct array in c. I gave it a shot but i keep getting an assortment of errors. The... (0 Replies)
Discussion started by: bjhum33
0 Replies

8. Shell Programming and Scripting

[Solved] Help with Sort command (ksh)

hello everyone, I have file with de-limited values in random order shown below, where C1V0 represents column1 value1, C2V0 represents column2 value 2, and so on. Column0 is a constant value which i didn't represent in the sample input format. Column1 is a numeric column. Column2 is a... (0 Replies)
Discussion started by: angie1234
0 Replies

9. Shell Programming and Scripting

[Solved] AIX ksh script -d <- what does it mean?

I'm looking at a line in a script: && DRROOT="/dir1" || DRROOT="/dir2" I'm trying to understand it. Is there a "-d" command and is it seeing if /dir1 exists and, if so, set an environment variable named DRROOT to "/dir1", else set DRROOT to "/dir2" ? Thanks, -dog ---------- Post... (0 Replies)
Discussion started by: landog
0 Replies

10. Shell Programming and Scripting

[SOLVED] Scope of KSH Variable in Perl?

cat test.ksh #!/usr/bin/ksh VAR="Dear Friends \n How are you? \n Have a nice day \n" export VAR echo "Inside test.ksh"; ./test.pl cat test.pl #!/usr/bin/perl print "Inside test.pl \n"; print "$VAR"; Output: ./test.ksh Inside test.ksh Inside test.plWhat I want to achieve is, I... (1 Reply)
Discussion started by: dahlia84
1 Replies
Login or Register to Ask a Question