Sponsored Content
Full Discussion: Array in Bash!
Top Forums Shell Programming and Scripting Array in Bash! Post 302606053 by Corona688 on Friday 9th of March 2012 11:58:47 AM
Old 03-09-2012
You forgot a line:

Code:
        *) # All other arguments

That's not pseudocode. The * accepts all arguments that weren't matched by -n or -m before it.

Also, you left some important spaces out of your while-statement:

Code:
while ["$#" -gt 0 ] # Wrong
while [ "$#" -gt 0 ] # Right

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash array

I'm trying to move files based on a certain day..my question is on array's, what's wrong with the way I'm stepping through the array? what i have gives me syntax errors..any ideas...so far I have #! /bin/bash sun_d=`cal |grep -v |awk '{printf " " $1}' ` echo "$sun_d" ls -l... (1 Reply)
Discussion started by: gubten
1 Replies

2. Shell Programming and Scripting

bash array problem

hi friends., i have two files yy.dat and mm.dat containing 110 elements in each if i read them into variables it is just showing only 4 elements instead of 110 elements My script is like this ################################## /bin/bash declare -a yy=(`cat yy.dat`) echo "No of values in... (1 Reply)
Discussion started by: yagnesh
1 Replies

3. OS X (Apple)

Associated Array in bash

I am using code as below to save data in associated array on Mac OS 10.8. #!/bin/sh storyboardExt=".storyboard" stringsExt=".strings" newStringsExt=".strings.new" oldStringsExt=".strings.old" localeDirExt=".lproj" baseLprojDir="Base${localeDirExt}" echo "${baseLprojDir}" # Find... (2 Replies)
Discussion started by: mikezang
2 Replies

4. Shell Programming and Scripting

Bash array manipulation

seeking assistance on comparing two arrays using bash: array1=(disk1, disk2, disk3, disk5, disk7, vol1, vol2, vol3, vol4, vol5) array2=(disk2, disk5 vol2, vol4 ) 1) if two arrays have same elements; EXIT else populate array3 & array4 with elements that are different between array1 & array2 as:... (3 Replies)
Discussion started by: solaix14
3 Replies

5. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

6. UNIX for Dummies Questions & Answers

Help with bash array

Hi, I would like to remove audio tracks from several video clips contained in a single directory using the command files=(*.mpg); ffmpeg -i "${files}" -vcodec copy -an na/output.mpg I want each processed file outputted to the sub-directory na retaining the original file name, how do I do that?... (4 Replies)
Discussion started by: jeppe83
4 Replies

7. Shell Programming and Scripting

Array Issue In Bash

Hi, I have the following code which is giving error mentioned below. Please can you support on this. Also suggest how can we access all the items against single vasservicename in circlename array,i.e, vasservicename say MTSTV will be available to all circles which are mentioned in the array... (2 Replies)
Discussion started by: siramitsharma
2 Replies

8. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

9. Shell Programming and Scripting

Bash Array connectin to another Array

Hello, i have a script that i need account_number to match a name. for exsample : ACCOUNT_ID=(IatHG8DC7mZbdymSoOr11w KbnlG2j-KRQ0-1_Xk356s8) and i run a loop curl requst with this the issue is that i want to know on which account were talking about so bash will know this : ... (4 Replies)
Discussion started by: batchenr
4 Replies

10. Shell Programming and Scripting

Bash for loop array

Hi there, A bit new to bash and am having an issue with a for loop. I look for filenames in a specified directory and pull the date string from each meeting a certain criteria, and then would like to make a directory for each date found, like this: search 20180101.gz 20180102.gz 20180103.gz... (5 Replies)
Discussion started by: mwheeler12
5 Replies
Sub::Quote(3)						User Contributed Perl Documentation					     Sub::Quote(3)

NAME
Sub::Quote - efficient generation of subroutines via string eval SYNOPSIS
package Silly; use Sub::Quote qw(quote_sub unquote_sub quoted_from_sub); quote_sub 'Silly::kitty', q{ print "meow" }; quote_sub 'Silly::doggy', q{ print "woof" }; my $sound = 0; quote_sub 'Silly::dagron', q{ print ++$sound % 2 ? 'burninate' : 'roar' }, { '$sound' => $sound }; And elsewhere: Silly->kitty; # meow Silly->doggy; # woof Silly->dagron; # burninate Silly->dagron; # roar Silly->dagron; # burninate DESCRIPTION
This package provides performant ways to generate subroutines from strings. SUBROUTINES
quote_sub my $coderef = quote_sub 'Foo::bar', q{ print $x++ . " " }, { '$x' => }; Arguments: ?$name, $code, ?\%captures, ?\%options $name is the subroutine where the coderef will be installed. $code is a string that will be turned into code. "\%captures" is a hashref of variables that will be made available to the code. The keys should be the full name of the variable to be made available, including the sigil. The values should be references to the values. The variables will contain copies of the values. See the "SYNOPSIS"'s "Silly::dagron" for an example using captures. options o no_install Boolean. Set this option to not install the generated coderef into the passed subroutine name on undefer. unquote_sub my $coderef = unquote_sub $sub; Forcibly replace subroutine with actual code. If $sub is not a quoted sub, this is a no-op. quoted_from_sub my $data = quoted_from_sub $sub; my ($name, $code, $captures, $compiled_sub) = @$data; Returns original arguments to quote_sub, plus the compiled version if this sub has already been unquoted. Note that $sub can be either the original quoted version or the compiled version for convenience. inlinify my $prelude = capture_unroll '$captures', { '$x' => 1, '$y' => 2, }; my $inlined_code = inlinify q{ my ($x, $y) = @_; print $x + $y . " "; }, '$x, $y', $prelude; Takes a string of code, a string of arguments, a string of code which acts as a "prelude", and a Boolean representing whether or not to localize the arguments. capture_unroll my $prelude = capture_unroll '$captures', { '$x' => 1, '$y' => 2, }, 4; Arguments: $from, \%captures, $indent Generates a snippet of code which is suitable to be used as a prelude for "inlinify". $from is a string will be used as a hashref in the resulting code. The keys of %captures are the names of the variables and the values are ignored. $indent is the number of spaces to indent the result by. CAVEATS
Much of this is just string-based code-generation, and as a result, a few caveats apply. return Calling "return" from a quote_sub'ed sub will not likely do what you intend. Instead of returning from the code you defined in "quote_sub", it will return from the overall function it is composited into. So when you pass in: quote_sub q{ return 1 if $condition; $morecode } It might turn up in the intended context as follows: sub foo { <important code a> do { return 1 if $condition; $morecode }; <important code b> } Which will obviously return from foo, when all you meant to do was return from the code context in quote_sub and proceed with running important code b. pragmas "Sub::Quote" preserves the environment of the code creating the quoted subs. This includes the package, strict, warnings, and any other lexical pragmas. This is done by prefixing the code with a block that sets up a matching environment. When inlining "Sub::Quote" subs, care should be taken that user pragmas won't effect the rest of the code. SUPPORT
See Moo for support and contact information. AUTHORS
See Moo for authors. COPYRIGHT AND LICENSE
See Moo for the copyright and license. perl v5.18.2 2013-12-31 Sub::Quote(3)
All times are GMT -4. The time now is 10:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy