Hi fishermen,
As a newbie I played around with fish 2.0 (Mac Os 10.7),
which looks handy, ( I hoped for the ability to move the
insertion point by clicking the mouse, but no :( , alas!)
Anyhow:
The following example is from the paragraph Variable Expansion
in http://fishshell.com/docs/2.2/index.html
set foo a b c
set a 10; set b 20; set c 30
for i in (seq (count $$foo))
echo $$foo[$i]
end
I think it would be clearer (and more efficient :-) if the authors
removed one of the $ signs in (count $$foo), since it’s the number of
elements in foo that we need, but those elements do not
have to be dereferenced at this point yet: we don’t need
the values of a, b and c, just how many symbols are in the list,
right?
So IMHO the example would be better like so:
set foo a b c
set a 10; set b 20; set c 30
for i in (seq (count $foo))
echo $$foo[$i]
end
Running this (with two elements ‘x' and ‘y' added to foo),
the improved code, now using (count $foo) results in 5
printed lines, two of which are blank, because x and y
have no values:
# set foo a x b y c
# for i in (seq (count $foo))
echo $$foo[$i]
end
10
20
30
#
After this I tried the old version with double dereferencing
(count $$foo) with foo having the value a x b y c, which
- unexpected by me - gave unwanted output, namely
just 3 printed lines, but not the ones you would like to see,
# set foo a x b y c
# set a 10; set b 20; set c 30
# for i in (seq (count $$foo))
echo $$foo[$i]
end
10
20
#
The valueless elements x and y apparently don’t count
for the number of elements in the value of foo!
So only three of the five (non)variable values were printed.
Indeed, testing this afterwards:
# count $$foo
3
# count $foo
5
IMHO Another reason to change the original code in the example.
How to print just the values of actual variables (a b and c), without
blank lines (for the x an y) is left as an exercise for those who read
this till the end. (Took me much more experimenting than I expected,
it required reading beyond the tutorial).
Henk
------------------------------------------------------------------------------
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users