Sponsored Content
Full Discussion: Shell string array
Top Forums Shell Programming and Scripting Shell string array Post 302641287 by Roy987 on Wednesday 16th of May 2012 02:55:41 AM
Old 05-16-2012
Shell string array

Hi all,

I want to create an array variable in shell, for example:
Code:
#!/bin/sh
name[0]="foo"
name[1]="bar"
name[2]="baz"

But above code didn't work, I also tried with:
Code:
name=(foo bar baz)

and
Code:
set -A name foo bar baz

but none of these worked.

Another question is how to know the shell version on my Ubuntu system?
I tried
Code:
/bin/sh --version

and
Code:
sh --version

, but both failed.

Thanks for your help.
Roy987

Last edited by Roy987; 05-16-2012 at 07:32 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

string to array

Hi Experts, I'm new to Shell Scripting world and need a little help from you "Scripting Gurus". I want to convert a string (entered by a user) to array in csh. I want something like this: echo "Enter the Numbers: " set num = $< Suppose, user enters: 1 2 3 4 5 6 7 This... (6 Replies)
Discussion started by: sumitgarg
6 Replies

2. Shell Programming and Scripting

How to hold string array in shell scripts

Gents, Below is the Shell script which I am trying to hold a string of array that is passed from a java file. But it is not working . Can any one please help me to by fixing it. #!/bin/csh/ set copy = ($argv) echo $copy >> /home/users/bavananr/rrr.log echo $copy >>... (3 Replies)
Discussion started by: brajesh
3 Replies

3. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

4. Homework & Coursework Questions

passing letters from an array into a string for string comparison

attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now. ##I have an array $wordString that initializes to a string of dashes ##reflecting the number of letters in $theWord ##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies

5. Shell Programming and Scripting

split string into array in shell

Hi all, I want to split a string into array based on given delimiter, for example: String: "foo|bar|baz" with delimiter "|" into array: strArr to strArr with values foo, bar and baz. Thanks a lot. Roy987 (5 Replies)
Discussion started by: Roy987
5 Replies

6. Shell Programming and Scripting

How to use string in array name?

Hi, I'm the beginner in bash scripting and I just want to create loop, which will create a few tables with string in name, and each time i try to do this in the following way, I receive: a=1; while do echo "Plik a=$a" for m in {1..4} do echo "Plik m=$m" ... (7 Replies)
Discussion started by: masterqu
7 Replies

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

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

9. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 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
Method::Signatures::Modifiers(3pm)			User Contributed Perl Documentation			Method::Signatures::Modifiers(3pm)

NAME
Method::Signatures::Modifiers - use Method::Signatures from within MooseX::Declare SYNOPSIS
use MooseX::Declare; use Method::Signatures::Modifiers; class Foo { method bar (Int $thing) { # this method is declared with Method::Signatures instead of MooseX::Method::Signatures } } # -- OR -- use MooseX::Declare; class My::Declare extends MooseX::Declare { use Method::Signatures::Modifiers; } # ... later ... use My::Declare; class Fizz { method baz (Int $thing) { # this method also declared with Method::Signatures instead of MooseX::Method::Signatures } } DESCRIPTION
Allows you to use Method::Signatures from within MooseX::Declare, both for the "method" keyword and also for any method modifiers ("before", "after", "around", "override", and "augment"). Typically method signatures within MooseX::Declare are provided by MooseX::Method::Signatures. Using Method::Signatures instead provides several advantages: o MooseX::Method::Signatures has a known bug with Perl 5.12.x which does not plague Method::Signatures. o Method::Signatures may provide substantially better performance when calling methods, depending on your circumstances. o Method::Signatures error messages are somewhat easier to read (and can be overridden more easily). However, Method::Signatures cannot be considered a drop-in replacement for MooseX::Method::Signatures. Specifically, the following features of MooseX::Method::Signatures are not available to you (or work differently) if you substitute Method::Signatures: Types for Invocants MooseX::Method::Signatures allows code such as this: method foo (ClassName $class: Int $bar) { } Method::Signatures does not allow you to specify a type for the invocant, so your code would change to: method foo ($class: Int $bar) { } "where" Constraints MooseX::Method::Signatures allows code like this: # only allow even integers method foo (Int $bar where { $_ % 2 == 0 }) { } Method::Signatures does not currently allow this, although it is a planned feature for a future release. Parameter Aliasing (Labels) MooseX::Method::Signatures allows code like this: # call this as $obj->foo(bar => $baz) method foo (Int :bar($baz)) { } This feature is not currently planned for Method::Signatures. Placeholders MooseX::Method::Signatures allows code like this: method foo (Int $bar, $, Int $baz)) { # second parameter not available as a variable here } This feature is not currently planned for Method::Signatures. Traits In MooseX::Method::Signatures, "does" is a synonym for "is". Method::Signatures does not honor this. Method::Signatures supports several traits that MooseX::Method::Signatures does not. MooseX::Method::Signatures supports the "coerce" trait. Method::Signatures does not currently support this, although it is a planned feature for a future release, potentially using the "does coerce" syntax. BUGS, CAVEATS and NOTES Note that although this module causes all calls to MooseX::Method::Signatures from within MooseX::Declare to be completely replaced by calls to Method::Signatures (or calls to Method::Signatures::Modifiers), MooseX::Method::Signatures is still loaded by MooseX::Declare. It's just never used. The "compile_at_BEGIN" flag to Method::Signatures is ignored by Method::Signatures::Modifiers. This is because parsing at compile-time can cause method modifiers to be added before the methods they are modifying are composed into the Moose classes. Parsing of methods at run- time is compatible with MooseX::Method::Signatures. THANKS
This code was written by Buddy Burden (barefootcoder). The import code for replacing MooseX::Method::Signatures is based on a suggestion from Nick Perez. LICENSE
Copyright 2011 by Michael G Schwern <schwern@pobox.com>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html SEE ALSO
MooseX::Declare, Method::Signatures, MooseX::Method::Signatures. perl v5.14.2 2012-06-03 Method::Signatures::Modifiers(3pm)
All times are GMT -4. The time now is 03:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy