Array problems in CSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array problems in CSH
# 1  
Old 02-24-2009
Array problems in CSH

Hi all,

I want to use some commands and I wrap them into an array, like follows:
Code:
set ALIAS_AR = ( "ls -ltr|wc -l"       \
                       "ps -ef|grep -v grep |grep tty|wc -l"     \
                       "who|wc -l"    )

Then I use a while loop to call every step:
Code:
set no = 1
while ( $no <= $#ALIAS_AR )
if ( `$ALIAS_AR[$no]` == 7 ) then echo "true" else echo "False" endif @ no++
end

And the script can't be ran as there are several problems, like
ls: invalid option -- '|'

Can anyone give me a suggestion about this?
PS: the above code is just demo, I want to use the pre-stored command to retrieve the status of running time.

Thanks
# 2  
Old 02-24-2009
I mean how I can use the commands list in an array, or even aliases I created...
# 3  
Old 02-24-2009
I just realized that this is not a problem about array, it is problem just like follows:
set CMD = "ls -ltr|wc -l"
`$CMD` or $CMD are all wrong, can any one give me a solution if I want to use the command like this way?
# 4  
Old 02-24-2009
The simplest way you can do this is like this

for ex:
CMD="ls -l | wc -l"

echo $CMD | /bin/sh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problems passing strings within an array

i have a list of apps that i need to forcequit and, from time to time, that list changes. perfect excuse to manage a single array! however, my strings with spaces aren't passing as i'd like them to. here's the simple script: #!/bin/sh #-----Array apps=( firefox-bin firefox... (6 Replies)
Discussion started by: hungryd
6 Replies

2. Shell Programming and Scripting

problems with ksh array and find command

set -A allfiles `find $usrhtml -type f` i am trying to populate this array with the find command. It works fine when find is looking through a single directory but when i add a new subdirectory the files in the subdirectory get duplicated. Can anyone help me and fix this so each files in... (1 Reply)
Discussion started by: bjhum33
1 Replies

3. Shell Programming and Scripting

4x4 Array in csh scripting

I am trying to code a 4 by 4 array. However the naming convention is diffrent. Please refer the image below https://lh5.googleusercontent.com/-Dl0vdjfXtU0/Tnh02_ORJpI/AAAAAAAAAKU/4c2zyFP9IB0/array.JPG I want to name them in order : from 0 to 3 --> (0,0) cell to (0,3) from 4 to 7 --> (1,0)... (0 Replies)
Discussion started by: animesharma
0 Replies

4. Shell Programming and Scripting

csh array missing some elements

I'm having a problem with this bit of my script. '/tmp/data' contains the output of 'ls -l', and I'm assigning a couple of the columns to an array. The problem is that it line starts on the third line of 'ls -l' rather than the first one. @ count = 7 set line = `cat /tmp/data` while ($count... (1 Reply)
Discussion started by: tkirk
1 Replies

5. Shell Programming and Scripting

Perl - Problems iwith colors while printing from dynamic array at runtime..

Hi Perl folks, I am having problems printing elements from an array at runtime. I wish to push elements into array at runtime and the print it later. Now I wish to print this matrix using colors. So I do something like this to enter the runtime values in array: ... (1 Reply)
Discussion started by: som.nitk
1 Replies

6. Shell Programming and Scripting

csh array help!!

I'm trying call the first item in the array then put it in a loop to call the next items in order. set $p = (port-1, port-2, port-3, port-4, exit) <sourcePort>daughtercard:$P</sourcePort> if ($p == "exit") then break else ($p >> 1) I know the above code isn't correct. I'm... (1 Reply)
Discussion started by: drkelly76
1 Replies

7. Shell Programming and Scripting

AWK in CSH script problems

Hello Guys, I was trying to obtain the information from the /etc/passwd file, here was my script: 38 echo -n "What's your login name? " 39 set logname=$< 40 echo "Your login name is $logname, your user's ID is `grep $logname /etc/passwd|awk -F: '{print $3}'`" 41 echo " Your home dir is... (1 Reply)
Discussion started by: tpltp
1 Replies

8. Shell Programming and Scripting

How to define array in Bourne shell , csh & ksh

Dear friends... Kindly if any one can help me to know the differences in definning & retreiving data from arrays in the sh,csh & ksh. I always facing problems in this issue. thanks...:) BR (3 Replies)
Discussion started by: ahmad.diab
3 Replies

9. Shell Programming and Scripting

associate array problems in awk

hi, i have 3 fields in a file and linked them through 2 associative arrays.. the problem is one of the associative array is working while the other is not.. the code part is: awk ' BEGIN { FS="|" rc = getline < "ICX_RULES" while ( rc == 1 ) { rule_id=$1 rule_parameter=$2... (2 Replies)
Discussion started by: aami_sayan
2 Replies

10. Shell Programming and Scripting

command substitution problems with csh using grep

I am trying to set a command into a variable in a csh script using command substituion with ``. I am having a problem with ps command combined with grep. The command is as follows (shows processes running with the word gpts in them). /usr/ucb/ps axwww | grep gpts this works fine at the... (2 Replies)
Discussion started by: voodoo31
2 Replies
Login or Register to Ask a Question