On Tue, Jun 16, 2009 at 8:22 PM, James Aguilar<[email protected]> wrote:
> Hey guys,
> I'm a relatively new fish user and I've been doing a little scripting with
> it.  I want to create a function that "returns" an array (in the sense that
> I can use it to set a variable to an array in a command substitution, like:
> set -l a_variable (my_array_emitting_function)
> Is it possible to do this in Fish?  Another thing that would be nice is to
> be able to set an array directly to a variable.  For example:
> set -l another_variable [1 2 3]

You can do these like this:
> set var a b
> echo $var
a b
> echo $var[1]
a
> function foo
    echo -e "A\nB\nC"
end
> set var (foo)
> echo $var
A B C

See http://fishshell.org/user_doc/commands.html#set

> And lastly, to be able to iterate over an array of arrays in a for loop.
>  For example:
> for my_array in [1 2] [2 3] [3 4]
>    echo $my_array[1] $my_array[2]
> end

I don't understand the intention here, nor the desired output. See:
http://fishshell.org/user_doc/index.html
http://fishshell.org/user_doc/commands.html#for
http://fishshell.org/user_doc/index.html#expand

A for loop iterates over a one-dimensional array:

> for var in val1 val2 val3; ...; end

A pattern can be constructed using braces:

> for var in {1,2}:{a,b}; echo $var; end
1:a
2:a
1:b
2:b

An array of arrays can be created and accessed like this:

> set a b c
> set b 1 2
> set c 3 4
> echo $$a[2]
3 4
> echo $$a[2][1]
4

Regards,
Philip

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to