On 8/17/06, Martin Baehr <[EMAIL PROTECTED]> wrote:
> On Wed, Aug 16, 2006 at 08:25:50PM -0400, James Vega wrote:
> > If I recall correctly, Fish doesn't use [] to perform alternation. Why
> > have two different ways of doing the same thing? {7,8} works just as
> > well and is more useful in general.
>
> no it's not.
> [78] should only expand to existing files.
> {7,8} should always expand to every possible combination:
You are correct that [] and {} are not identical, but fish does not
have both because they are so strongly related, just as Jamessan said.
>
> > ls
> > touch foo{1,2,3}
> > ls
> foo1 foo2 foo3
> > ls foo[12345]
> ls: foo[12345]: No such file or directory
> > ls foo{1,2,3,4,5}
> ls: foo4: No such file or directory
> ls: foo5: No such file or directory
> foo1 foo2 foo3
> > bash
> $ ls foo[12345]
> foo1 foo2 foo3
> $ ls foo{1,2,3,4,5}
> ls: foo4: No such file or directory
> ls: foo5: No such file or directory
> foo1 foo2 foo3
>
> $ ls foo[45]
> ls: foo[45]: No such file or directory
> $ shopt -s nullglob
> $ ls foo[45]
> foo1 foo2 foo3
> $ shopt -s failglob
> $ ls foo[45]
> bash: no match: foo[45]
>
> since it is potentially harmful to give nonexisting filenames to
> programs (touch is one example, if you do not want to create new files)
> being able to expand to only existing files is rather important.
I have found that in all such situations I have encountered in the
real world, it has been easy to sneak in a ?-wildcard somewhere in a
safe manner to only get the files that really exist. That said, there
might be situations where this is indeed not possible. If so, I would
suggest the inclusion of a null-wildcard-operator, one that does not
match any output, but all non-existing paths are dropped. This would
be useful in many other situations, e.g. to filter out non-existing
files from the output of a command substitution or a variable
expantion.
The idea here would be to instead of having two nearly-identical
features, like {} and [], to have two unrelated features that together
do all the things you could do previously and many that were very
cumbersome before as well.
Another thing worth considering is how often you'd want to use this
null-wildcard. Only things that are common enough that writing it out
as a command would be cumbersome should be made into operators of the
language itself. One could easily write a 'isfile' shellscript that
takes any number of arguments and outputs only the ones that are a
file to stdout.
function isfile
for i in $argv
test -f $i; and echo $i
end
end
Then you could write
touch (isfile foo{1,2,3})
instead of
touch foo[123]
the former is admittedly much longer/uglier, but if this is done very
rarely, that should be offset by the fact that it is easier to learn a
small language, that it is easier to find out what the code does if it
contains only functions and commands instead of weird operators, etc..
> note that i am not asking to copy bash, only for some way to selectively
> expand to existing matches. if there are no matches then the command
> should abort (like bashs nondefault failglob setting)
This is how fish operates today - if there are wildcards in a command,
and none of them produce a match, then the command is not executed.
This is also the default in csh. One of the few ways csh is much nicer
than Bourne shells for scripting.
>
> greetings, martin.
> --
> cooperative communication with sTeam - caudium, pike, roxen and unix
> offering: programming, training and administration - anywhere in the world
> --
> pike programmer travelling and working in europe open-steam.org
> unix system- bahai.or.at iaeste.(tuwien.ac|or).at
> administrator (caudium|gotpike).org is.schon.org
> Martin Bähr http://www.iaeste.or.at/~mbaehr/
--
Axel
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users