On 5/15/06, Beni Cherniavsky <[EMAIL PROTECTED]> wrote:
On 5/15/06, Philip Ganchev <[EMAIL PROTECTED]> wrote:
> On 5/13/06, Beni Cherniavsky <[EMAIL PROTECTED]> wrote:
> > The top level of a command line is list_concat() but it's not
> > availiable otherwise.
>
>    set ar3 $ar1 $ar2
>
Well, that's a command.

True, but it's available whenever you want to use it; just expand each
array in turn.  The exception, as we have seen, is inside brackets.


> You can achieve the fgrep expression as
>
>     fgrep -f' '{ls *.words}
>
I don't think that works.  It looks the same, but fgrep would get
arguments containing spaces: '-f some.words' '-f other.words', which
won't work.

Oops!  True.  Well with this example it is enough to remove the space
after "-f".

> and handle cases with three arrays, inline as
>
>     for a in $arr1
>         for b in $arr2
>             for c in $arr3
>                 echo $a\n$b\n$c
>             end
>         end
>     end
>
Verbose but works.

Oh, I don't know what I was thinking.  Here is the shortest
newline-safe implementation I can write.  It's verbose, but simple to
write and understand.

   set i 1
   for a in $arr1
       for b in $arr2
           for c in $arr3
               set arr[$i] $a
               set i (echo $i+1 | bc)
               set arr[$i] $b
               set i (echo $+1 | bc)
               set arr[$i] $c
               set i (echo $+1 | bc)
           end
       end
   end

> > Note that all implementations using external commands suffer from
> > false splitting if any word contains newlines.
> [...]
>
> To avoid this, you can use "set newArray[$i] oldArray1[$j]", instead
> of "echo".
>
> > [...] I hacked perlish references int the flat data structures of fish.
> [...]
>
[...]
It's not enough to solve newline-sensitivity at command-line parsing
time.  Any shell script relies on commands like `ls` and `grep`.  To
really solve it, you must provide filesystem access and data
processing as part of the language - but then it's not a shell any
longer.

The problem of populating array elements is different than the problem
of safely using the array elements, which is solved by using array
indexing, rather than newlines.

Microsoft Vista's planned shell, MSh, would have fixed the former
problem, being object-oriented.


[...]
Or perhaps if ``(...)`` tried to split on null bytes before trying
newlines, it would provide enough practical safety with file names and
commands like ``find -print0``.  This idea I actually like.

*Sigh* Unix should have outlawed newlines in file names...

But again, this would not solve the problem in general, just for file lists.


-------------------------------------------------------
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&kid0709&bid&3057&dat1642
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to