Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: grammar triviality with '&&'



02.03.2015, 21:54, "Kurtis Rader" <krader@xxxxxxxxxxxxx>:
> On Mon, Mar 2, 2015 at 8:17 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>>  if [ -e 'shelly.txt' ]
>>  && [ -n "$ozymandias" ]
>>  && [ grep "I met a traveler" ]
>>  then
>>    echo "Look on my works, ye mighty"
>>  fi
>
> Why are you using ancient Bourne-shell syntax? If you need compatibility
> with the Bourn-shell you can't use the feature you're asking for. If you
> use the slightly less ancient Korn-shell syntax you can break the test
> across lines the way you want:
>
> #!/bin/zsh
> ozymandia=yes
>
> if [[ -e 'shelly.txt'
>    && -n "$ozymandia"
>    && -n $(grep "I met a traveler" shelly.txt) ]]
> then
>     echo "Look on my works, ye mighty"
> fi
>
> Note that I fixed your command as "grep" isn't a valid test; although, I
> wouldn't write it that way in practice as it isn't efficient.
>
> P.S., Are you aware that in the days of the Bourne-shell that the shell did
> not interpret tests like "-e" it simply ran the "[" command and checked its
> exit status. In fact that command should still exist on your system as a
> hardlink to the "test" command. Run
>
> $ ls -li '/bin/[' /bin/test
> 123034700 -rwxr-xr-x  2 root  wheel  18480 Sep  9 15:44 /bin/[*
> 123034700 -rwxr-xr-x  2 root  wheel  18480 Sep  9 15:44 /bin/test*

Why hardlink and why in /bin?

% la /usr/bin/{test,\[}
-rwxr-xr-x 1 root 39K янв 31 04:03 /usr/bin/[*
-rwxr-xr-x 1 root 35K янв 31 04:03 /usr/bin/test*

: you see there is a 4K difference. Not sure why, but both belong to coreutils package.

>
> to see this.
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank



Messages sorted by: Reverse Date, Date, Thread, Author