On Wed, Jun 17, 2009 at 2:44 PM, James Aguilar<[email protected]> wrote:
> On Tue, Jun 16, 2009 at 19:55, Philip Ganchev <[email protected]>
> wrote:
[...]
> This is the closest to what I want. Is there any way to get something like
> this:
>
>> for var in [something]; echo $var[1] "->" $var[2]; end
> 1 -> a
> 2 -> b
>
> Where I can easily access each field separately (e.g. with array
> subscripts)?
>
> I know I can do
>> for var in "1:a" "2:b"; echo $var; end
>
> But that doesn't give me easy access the fields using array
> indexing. The best I can think of right now is to define a separate function get_fields (gf for short):
>
> function gf --description Get\ one\ field\ from\ a\ colon\ separated\ field\
> list.
> echo $argv[1] | awk -F":" '{ print $'$argv[2]' }'
> end
>
> And then I can do this:
> [...]> for var in "1:a" "2:b"; echo (gf $var 1) "->" (gf $var 2); end
> 1 -> a
> 2 -> b
> Which is what I want, but maybe a little more verbose than my true desire.
I don't understand why you would want to access the fields, but you can do:
for v in 1:a 2:b
# Create a new array variable
set w (echo $v | tr : \n)
# Use the new array variable
echo $w[2] "->" $w[1]
end
Interestingly, here you cannot use an array of arrays:
set x 1 a
set y 2 b
for v in x y
echo $$v[2] "->" $$v[1]
end
fish: Array index out of bounds
echo $$v[2] "->" $$v[1]
for v in x y
echo $"$v"[2] "->" $"$v"[1]
end
fish: Did you mean (COMMAND)? In fish, the “$” character is only used
for accessing variables. To learn more about command substitution in
fish, type “help expand-command-substitution”.
echo $"$v"[2] "->" $$v[1]
Personally, I think that $"$v"[2] ought to be made to work.
------------------------------------------------------------------------------
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