Need help with array in C shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with array in C shell
# 1  
Old 11-27-2012
Need help with array in C shell

Hi all,
I'm newbie in shell. I'm trying to create files with user name select from database on title with .csh file. So my solution is select name from database into an array, and then foreach name I create a file with that name on title. Like this:
Code:
set Name[] = `sqlplus -s ${MYSQL}`  <<EOF
    WHENEVER SQLERROR EXIT SQL.SQLCODE
      SELECT NAME FROM TABLE;
    EXIT;
EOF

foreach name (${Name[*]})
    touch ${MYDIR}/${name}.xxx
¨

Anyone can solve this?
Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.


---------- Post updated at 04:50 PM ---------- Previous update was at 04:17 PM ----------

problem solved!
Dear mod,
Help me to close this. Thanks!

Last edited by leejung89; 11-27-2012 at 05:55 AM.. Reason: problem solved!
# 2  
Old 11-27-2012
I won't close the thread as you might get a better answer. Although we wouldn't know that unless you say how your problem was solved.
# 3  
Old 11-27-2012
Leejung, I believe you could share the solution of this issue Smilie
# 4  
Old 11-27-2012
well, I just fix like that
Code:
set Name = `sqlplus -s ${MYSQL}`  <<EOF
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET HEADING OFF
    SET COLSEP ' '
      SELECT NAME FROM TABLE;
    EXIT;
EOF

then I will have an array look like:
Code:
Name = (nameA nameB nameC)

Each items got 1 space separates them. Then I use this code below to read all name and create files
Code:
foreach name (${Name[*]})
    touch ${MYDIR}/${name}.xxx
end

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

3. Shell Programming and Scripting

Array in shell script

Hi, check=("/usr/local/bin/chk_nag | awk -F":" '{print $1}'" "/usr/local/bin/chk_kas | awk -F":" '{print $1}'" "/usr/local/bin/chk_was | awk -F":" '{print $1}'" ) for i in "${check}"; do echo $i; done when I run this. It says Syntax error: "(" unexpected Please advise. (5 Replies)
Discussion started by: ashokvpp
5 Replies

4. Shell Programming and Scripting

how to use array variables in shell

Hi, everyone. I wrote a code like this for f in HB021* do program done for f in HB034* do program done for f in HB056* do program done . . (5 Replies)
Discussion started by: xshang
5 Replies

5. Shell Programming and Scripting

Shell string array

Hi all, I want to create an array variable in shell, for example: #!/bin/sh name="foo" name="bar" name="baz" But above code didn't work, I also tried with: name=(foo bar baz) and set -A name foo bar baz but none of these worked. Another question is how to know the shell... (6 Replies)
Discussion started by: Roy987
6 Replies

6. Shell Programming and Scripting

Array in Shell

Hi, I have following issue while using Array in Shell script I have input file as below FILE1=filename1,filelocation1 FILE2=filename2,filelocation2 FILE3=filename3,filelocation3 FILE4=filename4,filelocation4 FILE5=filename5,filelocation5 FILE6=filename6,filelocation6 I want... (3 Replies)
Discussion started by: balasubramani04
3 Replies

7. Shell Programming and Scripting

Output of shell in array

Hi, i have a file which reads, arun/manager/200000 pradeep/engineer/10000 karthik/teamlead/30000 ..... i want an output to show, name role salary ======================= arun manager 200000 pradeep engineer 10000 and so on.. i want to do... (9 Replies)
Discussion started by: pradebban
9 Replies

8. Shell Programming and Scripting

Array indexing in shell

Hi , I have 4 array as below Input: servernames=(10.144.0.129 10.144.0.130 10.144.0.131) subfolder_129=(PSTN_SigtranCamel_03 PSTN_SigtranCamel_04 PSTN_SigtranCamel_05) subfolder_130=(SigtranCamel_11 SigtranCamel_12 SigtranCamel_13 SigtranCamel_14 SigtranCamel_15)... (4 Replies)
Discussion started by: sushmab82
4 Replies

9. 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

10. 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
Login or Register to Ask a Question