Sponsored Content
Top Forums Shell Programming and Scripting Need help with array in C shell Post 302736285 by leejung89 on Tuesday 27th of November 2012 04:50:24 AM
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!
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
DBIx::Class::Manual::QuickStart(3)			User Contributed Perl Documentation			DBIx::Class::Manual::QuickStart(3)

NAME
DBIx::Class::Manual::QuickStart - up and running with DBIC in 10 minutes DESCRIPTION
This document shows the minimum amount of code to make you a productive DBIC user. It requires you to be familiar with just the basics of database programming (what database tables, rows and columns are) and the basics of Perl object-oriented programming (calling methods on an object instance). It also helps if you already know a bit of SQL and how to connect to a database through DBI. Follow along with the example database shipping with this distribution, see directory examples/Schema. This database is also used through- out the rest of the documentation. Preparation First, install DBIx::Class like you do with any other CPAN distribution. See <http://www.cpan.org/modules/INSTALL.html> and perlmodinstall. Then open the distribution in your shell and change to the subdirectory mentioned earlier, the next command will download and unpack it: $ perl -mCPAN -e'CPAN::Shell->look("DBIx::Class")' DBIx-Class$ cd examples/Schema Inspect the database: DBIx-Class/examples/Schema$ sqlite3 db/example.db .dump You can also use a GUI database browser such as SQLite Manager <https://addons.mozilla.org/firefox/addon/sqlite-manager>. Have a look at the schema classes files in the subdirectory MyApp. The "MyApp::Schema" class is the entry point for loading the other classes and interacting with the database through DBIC and the "Result" classes correspond to the tables in the database. DBIx::Class::Manual::Example shows how to write all that Perl code. That is almost never necessary, though. Instead use dbicdump (part of the distribution DBIx::Class::Schema::Loader) to automatically create schema classes files from an existing database. The chapter "Resetting the database" below shows an example invocation. Connecting to the database A schema object represents the database. use MyApp::Schema qw(); my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); The first four arguments are the same as for "connect" in DBI. Working with data Almost all actions go through a resultset object. Adding data Via intermediate result objects: my $artist_ma = $schema->resultset('Artist')->create({ name => 'Massive Attack', }); my $cd_mezz = $artist_ma->create_related(cds => { title => 'Mezzanine', }); for ('Angel', 'Teardrop') { $cd_mezz->create_related(tracks => { title => $_ }); } Via relation accessors: $schema->resultset('Artist')->create({ name => 'Metallica', cds => [ { title => q{Kill 'Em All}, tracks => [ { title => 'Jump in the Fire' }, { title => 'Whiplash' }, ], }, { title => 'ReLoad', tracks => [ { title => 'The Memory Remains' }, { title => 'The Unforgiven II' }, { title => 'Fuel' }, ], }, ], }); Columns that are not named are filled with default values. The value "undef" acts as a "NULL" in the database. See the chapter "Introspecting the schema classes" below to find out where the non-obvious source name strings such as "Artist" and accessors such as "cds" and "tracks" come from. Set the environment variable "DBI_TRACE='1|SQL'" to see the generated queries. Retrieving data Set up a condition. my $artists_starting_with_m = $schema->resultset('Artist')->search( { name => { like => 'M%' } } ); Iterate over result objects of class "MyApp::Schema::Result::Artist". Result objects represent a row and automatically get accessors for their column names. for my $artist ($artists_starting_with_m->all) { say $artist->name; } Changing data Change the release year of all CDs titled ReLoad. $schema->resultset('Cd')->search( { title => 'ReLoad', } )->update_all( { year => 1997, } ); Removing data Removes all tracks titled Fuel regardless of which CD the belong to. $schema->resultset('Track')->search( { title => 'Fuel', } )->delete_all; Introspecting the schema classes This is useful for getting a feel for the naming of things in a REPL or during explorative programming. From the root to the details: $schema->sources; # returns qw(Cd Track Artist) $schema->source('Cd')->columns; # returns qw(cdid artist title year) $schema->source('Cd')->relationships; # returns qw(artist tracks) From a detail to the root: $some_result->result_source; # returns appropriate source $some_resultset->result_source; $some_resultsource->schema; # returns appropriate schema Resetting the database # delete database file DBIx-Class/examples/Schema$ rm -f db/example.db # create database and set up tables from definition DBIx-Class/examples/Schema$ sqlite3 db/example.db < db/example.sql # fill them with data DBIx-Class/examples/Schema$ perl ./insertdb.pl # delete the schema classes files DBIx-Class/examples/Schema$ rm -rf MyApp # recreate schema classes files from database file DBIx-Class/examples/Schema$ dbicdump -o dump_directory=. MyApp::Schema dbi:SQLite:db/example.db Where to go next If you want to exercise what you learned with a more complicated schema, load Northwind <http://code.google.com/p/northwindextended/> into your database. If you want to transfer your existing SQL knowledge, read DBIx::Class::Manual::SQLHackers. Continue with DBIx::Class::Tutorial and "WHERE TO START READING" in DBIx::Class. perl v5.18.2 2014-01-05 DBIx::Class::Manual::QuickStart(3)
All times are GMT -4. The time now is 02:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy