Besides shellscripts, what other scripting languages make the same distingction between single and double quotes?
As to $@, that is an excellent question! Arrays are one of the things I chose not to take up in this article. The article is rather long as it is already... The answer is that $@ is replaced by a general purpose array syntax.
The arguments to a function or program are stored in the 'argv' array variable. In fish, you access array elements with square brackets, so $argv is the first array element. $argv expands to a list of all elements. So to loop over the arguments to a function or program, you can just write:
for i in $argv
You can also do sublists by writing $argv[1 2 5] or $argv[(seq 2 7)]. The latter example uses a subshell inside an array subscript.
Assigning array variables is just as easy as assigning regular variables, and uses the same command:
set colors red breen glue
sets the variable 'colors' to have tha values 'red', 'breen' and 'glue'.
You can alter one element of an array using:
set colors green
to change the above array to 'red', 'green' and 'glue'
There is one last noteworthy thing about fish style arrays. Colon separated values found in the environment on startup are converted to arrays. So PATH , CDPATH and all the other colon-separated lists are arrays in fish. They are of course converted back into colon separated lists for all programs that fish spawns. The reason why fish hardcodes the colon character here instead of allowing the user to specify a separator character like IFS is that by hardcoding colon, it is possible to make sure that the values of variables are not altered by fish. It would be unfortunate if fish accidentally exported a tab-separated PATH to any programs it starts.
Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds