Re: [gelöst]Re: /bin/sh: prüfen ob String1 "Wort" aus String2 enthält
Hallo,
On Mon, 2 Jan 2017 02:15:25 +0100
Christian Knoke <chrisk@cknoke.de> wrote:
(...)
> etwas schöner und effizienter:
>
> #!/bin/bash
>
> PKGNAMES="anton caesar heinrich nordpol ludwig emil otto"
> INSTALLED_PKGS="anton berta caesar dora emil friedrich gustav heinrich"
>
> script='PKGS="" ; for p in $PKGNAMES ; do case $p in (nonsense'
> for i in $INSTALLED_PKGS ; do script=${script}\|$i ; done
> script=${script}') PKGS="$PKGS $p" ;; esac ; done ; echo $PKGS'
>
> eval ${script}
Wow, funktioniert sogar mit posh!
Interessant auch:
getestet und "gebenchmarkt" mit bash, dash & ksh:
mit bash und dash etwas langsamer als "meine" "case"-Schleife, mit ksh
dagegen ca. 10 mal so schnell!
Werde mir das noch mal in Ruhe ansehen müssen, um zu verstehen, wie's
funktioniert :-)
Gruss
Michael
.-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
War is never imperative.
-- McCoy, "Balance of Terror", stardate 1709.2
Reply to: