Sponsored Content
Top Forums Shell Programming and Scripting Array size in C shell scripting Post 303044460 by Chubler_XL on Saturday 22nd of February 2020 02:10:39 AM
Old 02-22-2020
Say you have four values in variable VALS like this a b c d then you can build an array containing these with a simple set statement.
Code:
$ set VALS="a b c d"
$ set master_array = ( $VALS )
$ echo ${#master_array}
4

or if you have 4 separate variables A1 thru A4 you could use eval like this:

Code:
set A1=a
set A2=b
set A3=c
set A4=d

set master_array =
set i = 1

while ( $i < 5 )
  set master_array = ( $master_array:q `eval echo \$A$i` )
  @ i++
end

 

10 More Discussions You Might Find Interesting

1. Programming

Array size

In a C program is there any limit on the size of an array? (4 Replies)
Discussion started by: Nadeem Mistry
4 Replies

2. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

3. UNIX for Advanced & Expert Users

MAX SIZE ARRAY Can Hold it

Hi, Do anyone know what's the max size of array (in awk) can be store before hit any memory issue. Regards (3 Replies)
Discussion started by: epall
3 Replies

4. Shell Programming and Scripting

Size of an array in sh shell script

Is there a way to find out the size of an array in sh shell script? Thanks. (1 Reply)
Discussion started by: trivektor
1 Replies

5. Programming

size of char array in c

i have to store a data more than 100000. i don't know the size of the data whether it may be 100000 or 1000000. so how can i define variable size; example char abc; but i don't know the size so how can i give array size?? in one sentence how can i give the array size dynamically so that i... (6 Replies)
Discussion started by: phani_sree
6 Replies

6. Shell Programming and Scripting

Use Awk and Array to get total size of files

Hello all, I need to do scripts total up the size in selected extension file for example motion.mov and segmentation.avi is in Label Media. For file info.doc and calc.xls in Label Document. I need output will be like this: count 1 Media,,2 GB count 2 Document,,4 GB My problem is,... (16 Replies)
Discussion started by: sheikh76
16 Replies

7. Shell Programming and Scripting

array + if in linux shell scripting

Hi, I am having two set of files with different number of columns and rows. A set of files have only single row with 20 columns. B set of files have 1000s of rows with 5 columns. both set contains equal number of files. I want to save all the 20 columns of A in variables one by one and... (21 Replies)
Discussion started by: CAch
21 Replies

8. Shell Programming and Scripting

Assigning array values using awk in shell scripting

hi My script as below #!/bin/ksh for i in `seq 1 7` do a=$(awk '{print $i}' /home/rama/expenese.txt) done for i in `seq 1 7` do echo "${a}" done content of expense.txt is as below 5032 210179 3110 132813874 53488966 11459221 5300794 I want output as... (6 Replies)
Discussion started by: Ramakrishna V
6 Replies

9. Shell Programming and Scripting

How to get the file size and count of a table using shell scripting?

Hi there, im a beginner to the shell scripting.i trying to extract a table from a db(IMD) and i have to get the count of that table and size of the file. can you help me out how to write the shall scriping for the above query. (2 Replies)
Discussion started by: pawanmamidi
2 Replies

10. UNIX for Beginners Questions & Answers

Convert String to an Array using shell scripting in JSON file.

This is the sample json I have pasted here. I want all the IP address strings to be converted into an array. For example "10.38.32.202" has to be converted to everywhere in the JSON. There are multiple IPs in a JSON I am pasting one sample object from the JSON. But the IPs already in an Array... (11 Replies)
Discussion started by: vinshas1
11 Replies
Perl::Critic::Policy::ErrorHandling::RequireCheckingRetuUserlContributed PPerl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval(3)

NAME
Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval - You can't depend upon the value of "$@"/"$EVAL_ERROR" to tell whether an "eval" failed. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
A common idiom in perl for dealing with possible errors is to use "eval" followed by a check of $@/$EVAL_ERROR: eval { ... }; if ($EVAL_ERROR) { ... } There's a problem with this: the value of $EVAL_ERROR can change between the end of the "eval" and the "if" statement. The issue is object destructors: package Foo; ... sub DESTROY { ... eval { ... }; ... } package main; eval { my $foo = Foo->new(); ... }; if ($EVAL_ERROR) { ... } Assuming there are no other references to $foo created, when the "eval" block in "main" is exited, "Foo::DESTROY()" will be invoked, regardless of whether the "eval" finished normally or not. If the "eval" in "main" fails, but the "eval" in "Foo::DESTROY()" succeeds, then $EVAL_ERROR will be empty by the time that the "if" is executed. Additional issues arise if you depend upon the exact contents of $EVAL_ERROR and both "eval"s fail, because the messages from both will be concatenated. Even if there isn't an "eval" directly in the "DESTROY()" method code, it may invoke code that does use "eval" or otherwise affects $EVAL_ERROR. The solution is to ensure that, upon normal exit, an "eval" returns a true value and to test that value: # Constructors are no problem. my $object = eval { Class->new() }; # To cover the possiblity that an operation may correctly return a # false value, end the block with "1": if ( eval { something(); 1 } ) { ... } eval { ... 1; } or do { # Error handling here }; Unfortunately, you can't use the "defined" function to test the result; "eval" returns an empty string on failure. Various modules have been written to take some of the pain out of properly localizing and checking $@/$EVAL_ERROR. For example: use Try::Tiny; try { ... } catch { # Error handling here; # The exception is in $_/$ARG, not $@/$EVAL_ERROR. }; # Note semicolon. "But we don't use DESTROY() anywhere in our code!" you say. That may be the case, but do any of the third-party modules you use have them? What about any you may use in the future or updated versions of the ones you already use? CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
See thread on perl5-porters starting here: <http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-06/msg00537.html>. For a nice, easy, non-magical way of properly handling exceptions, see Try::Tiny. AUTHOR
Elliot Shank "<perl@galumph.com>" COPYRIGHT
Copyright (c) 2008-2011 Elliot Shank. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.16.3 2014-0Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval(3)
All times are GMT -4. The time now is 01:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy