<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="http://cptsalek.twoday.net/rss2html.xsl" type="text/xsl"?>
<rdf:RDF 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  xmlns:cc="http://web.resource.org/cc/"
  xmlns="http://purl.org/rss/1.0/"
> 

  <channel rdf:about="http://cptsalek.twoday.net/">
    <title>Captains Log (Ich bin der Kapitän meines Lebens -- Segeln auf den Gestaden der Realität) : Rubrik:zsh</title>
    <link>http://cptsalek.twoday.net/</link>
    <description>Ich bin der Kapitän meines Lebens -- Segeln auf den Gestaden der Realität</description>
    <dc:publisher>cptsalek</dc:publisher>
    <dc:creator>cptsalek</dc:creator>
    <dc:date>2010-01-27T09:21:24Z</dc:date>
    <dc:language>en</dc:language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T00:00:00Z</sy:updateBase>
    <cc:license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/2.0/de/" />

    <image rdf:resource="http://static.twoday.net/cptsalek/images/icon.jpg" />
    <items>
      <rdf:Seq>
            <rdf:li rdf:resource="http://cptsalek.twoday.net/stories/5388622/" />
            <rdf:li rdf:resource="http://cptsalek.twoday.net/stories/4134498/" />
            <rdf:li rdf:resource="http://cptsalek.twoday.net/stories/3374324/" />
            <rdf:li rdf:resource="http://cptsalek.twoday.net/stories/3374010/" />

      </rdf:Seq>
    </items>
  </channel>

  <image rdf:about="http://static.twoday.net/cptsalek/images/icon.jpg">
    <title>Captains Log</title>
    <url>http://static.twoday.net/cptsalek/images/icon.jpg</url>
    <link>http://cptsalek.twoday.net/</link>
  </image>

  <item rdf:about="http://cptsalek.twoday.net/stories/5388622/">
    <title>permfix.zsh: Fix broken permissions</title>
    <link>http://cptsalek.twoday.net/stories/5388622/</link>
    <description>Yesterday I messed up my NetBSD system while moving /usr and /var to a new, encrypted partition. I didn&apos;t reckon that NetBSDs tar needs &quot;-p&quot; to preserve the meta information attached to a directory or file, so I lost ownerships, groups and especially permissions. And as I discovered the mess I already had continue with setting up the system, installing ports, pkgsrc, /usr/src and so on...&lt;br /&gt;
Luckily I didn&apos;t simply remove the original directories, but kept them as &quot;/usr.old&quot; and &quot;/var.old&quot;. So I wrote a small script using zsh and the &quot;zsh/stat&quot; module to fix it. So in case something like this might happen to you, too, here&apos;s a simple solution:
&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;&lt;code&gt;#!/usr/pkg/bin/zsh

zmodload zsh/stat

typeset srcdir dstdir 
typeset -A srcobj dstobj
typeset -i srcmode dstmode

[[ $# != 2 ]] &amp;&amp; {
    echo &quot;Error: ${0:t} requires exactly two arguments: sourcedir and destdir&quot;
    exit 1
}  
[[ ! -d $1 ]] &amp;&amp; {
    echo &quot;Error: $1 is not a directory or does not exist.&quot;
    exit 1
}
[[ ! -d $2 ]] &amp;&amp; {
    echo &quot;Error: $2 is not a directory or does not exist.&quot;
    exit 1
}

srcdir=$1
dstdir=$2

for obj in $( cd $srcdir ; find . )
do
    [[ -e $dstdir/$obj ]] &amp;&amp; {
        stat -oH srcobj $srcdir/$obj
        stat -oH dstobj $dstdir/$obj
        srcmode=${${srcobj[mode]}[4,7]}
        dstmode=${${dstobj[mode]}[4,7]}
        [[ $srcmode -ne $dstmode ]] &amp;&amp; {
            echo &quot;Changing $obj perm from $dstmode to $srcmode&quot;
            chmod $srcmode $dstdir/$obj
        }
        [[ $srcobj[uid] != $dstobj[uid] ]] &amp;&amp; {
            echo &quot;Changing $obj owner from $dstobj[uid] to $srcobj[uid]&quot;
            chown $srcobj[uid] $dstdir/$obj
        }
        [[ $srcobj[gid] != $dstobj[gid] ]] &amp;&amp; {
            echo &quot;Changing $obj group from $dstobj[gid] to $srcobj[gid]&quot;
            chgrp $srcobj[gid] $dstdir/$obj
        }
    }
done&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt; &lt;br /&gt;There might be a shorter solution, but I wanted to keep this simple and readable. ;-)</description>
    <dc:creator>cptsalek</dc:creator>
    <dc:subject>zsh</dc:subject>
    <dc:rights>Copyright &#169; 2008 cptsalek</dc:rights>
    <dc:date>2008-12-15T08:06:00Z</dc:date>
  </item>
  <item rdf:about="http://cptsalek.twoday.net/stories/4134498/">
    <title>I love zsh: Parameter Substitution</title>
    <link>http://cptsalek.twoday.net/stories/4134498/</link>
    <description>I&apos;m one of the guys who came across &lt;a href=&quot;http://www.zsh.org&quot;&gt;zsh&lt;/a&gt;, and use it since then. There has been an interesting thread about parameter substitution, with a summary of all the features that zsh provides. &lt;br /&gt;
Check out &quot;&lt;a href=&quot;http://www.zsh.org/mla/users//2007/msg00610.html&quot;&gt;RE: Very useful !#^&lt;/a&gt;.&lt;br /&gt;
It&apos;s great to be able to use parameters that have been supplied in the current line, or the line before. Just think about a long command. You press enter, and in the next line, you&apos;ll need a parameter again, such as a path name. With !:n, where n is a number that has to be substituted with the position number where the parameter is located.&lt;br /&gt;
&lt;br /&gt;
If you think &quot;&lt;i&gt;hey, what&apos;s this zsh stuff all about, there&apos;s bash!&lt;/i&gt;&quot;, check out the brilliant article &lt;a href=&quot;http://friedcpu.wordpress.com/2007/07/24/zsh-the-last-shell-youll-ever-need/&quot;&gt;The last shell you&apos;ll ever need&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Zusammenfassung:&lt;/b&gt;&lt;br /&gt;
Auf der &lt;a href=&quot;http://www.zsh.org/mla/users/&quot;&gt;zsh-Users&lt;/a&gt; Mailingliste kann man eine schicke Zusammenfassung der möglichen &lt;a href=&quot;http://www.zsh.org/mla/users//2007/msg00610.html&quot;&gt;Parameter Substitutionen&lt;/a&gt; lesen. Für den Fall, dass man auf Copy+Paste keine Lust hat, aber mal aus der vorherigen, oder aktuellen Zeile, einen Parameter (&quot;ein Wort&quot;) braucht.&lt;br /&gt;
Sehr gut ist übrigens der Artikel &lt;a href=&quot;http://friedcpu.wordpress.com/2007/07/24/zsh-the-last-shell-youll-ever-need/&quot;&gt;The last shell you&apos;ll ever need&lt;/a&gt;, bei dem es Vorteile der zsh geht. Korrekturen stehen dann in den Kommentaren. ;-)</description>
    <dc:creator>cptsalek</dc:creator>
    <dc:subject>zsh</dc:subject>
    <dc:rights>Copyright &#169; 2007 cptsalek</dc:rights>
    <dc:date>2007-08-03T19:59:00Z</dc:date>
  </item>
  <item rdf:about="http://cptsalek.twoday.net/stories/3374324/">
    <title>ZModules: stat</title>
    <link>http://cptsalek.twoday.net/stories/3374324/</link>
    <description>Der Funktionsumfang der zsh kann durch Module erweitert werden. Aufgelistet sind diese in der manpage zu &lt;a href=&quot;http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/zshmodules.1.html&quot;&gt;zshmodules&lt;/a&gt; (welche Überraschung).&lt;br /&gt;
&lt;br /&gt;
Eines davon ist das Module &lt;i&gt;zsh/stat&lt;/i&gt;, das Zugriff auf den gleichnamigen Systemcall bietet:

&lt;pre&gt;&lt;code&gt;
% zmodload zsh/stat
% touch somefile
% ls -l somefile
-rw-r--r--  1 cptsalek  1001  0 Feb 27 22:16 somefile
% stat somefile
device  98
inode   376964
mode    33188
nlink   1
uid     1001
gid     1001
rdev    0
size    0
atime   1172610986
mtime   1172610986
ctime   1172610986
blksize 4096
blocks  0
link
&lt;/code&gt;&lt;/pre&gt;

Ok, das geht natürlich auch in einem menschenlesbaren Format:

&lt;pre&gt;&lt;code&gt;
% stat -s somefile
device  98
inode   376964
mode    -rw-r--r--
nlink   1
uid     cptsalek
gid     1001
rdev    0
size    0
atime   Tue Feb 27 22:16:26
mtime   Tue Feb 27 22:16:26
ctime   Tue Feb 27 22:16:26
blksize 4096
blocks  0
link
&lt;/code&gt;&lt;/pre&gt;

Yepp, mit stat kann man alle Daten, die zu einem File gehlören, in einem Rutsch auslesen, ohne mit ls, grep und Co. irgendwelche Orgien zu feiern. Und weils so praktisch ist, kann man das die Ausgabe auch in ein Hash eintüten:

&lt;pre&gt;&lt;code&gt;
% stat -onH hash somefile
% echo ${${hash[mode]}[4,7]}
0644
&lt;/code&gt;&lt;/pre&gt;

...voila, womit man die Permissions erschlagen hätte.</description>
    <dc:creator>cptsalek</dc:creator>
    <dc:subject>zsh</dc:subject>
    <dc:rights>Copyright &#169; 2007 cptsalek</dc:rights>
    <dc:date>2007-02-27T21:35:00Z</dc:date>
  </item>
  <item rdf:about="http://cptsalek.twoday.net/stories/3374010/">
    <title>Muschelspaß</title>
    <link>http://cptsalek.twoday.net/stories/3374010/</link>
    <description>Ich weiß garnicht mehr wie, aber vor einer Weile bin ich über die &lt;a href=&quot;http://www.zsh.org&quot;&gt;zsh&lt;/a&gt; gestolpert. Und seitdem ist diese höchst komfortable und genial programmierbare Shell zu meinem Standard geworden.&lt;br /&gt;
Mäuschenschubser können an dieser Stelle übrigens aufhören zu lesen. ;-)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Warum?&lt;/b&gt;&lt;br /&gt;
Also da wäre z.B. die &lt;a href=&quot;http://www.michael-prokop.at/computer/tools_zsh_liebhaber.html&quot;&gt;ZSH-Liebhaberseite&lt;/a&gt;. &lt;br /&gt;
Eigentlich ist damit auch schon alles gesagt, meine Favoriten sind
&lt;ul&gt;&lt;li&gt;Arrays&lt;/li&gt;&lt;li&gt;Assoziative Arrays (&quot;Hashes&quot;)&lt;/li&gt;&lt;li&gt;Positionsparameter in Strings&lt;/li&gt;&lt;li&gt;Mächtige Parameter/Command/Argument-Expansion&lt;/li&gt;&lt;/ul&gt;

Hier mal einige Beispiele:

&lt;pre&gt;&lt;code&gt;
typeset -a array
array=( &quot;${(f)$(ls -l)}&quot; )
&lt;/code&gt;&lt;/pre&gt;

Diese kleine Codezeile liest die Ausgabe des ls-Befehls in ein Array ein, und zwar Zeilenweise. Ein spezielles Konstrukt gibt es für Dateien, mit dem man auf cat verzichten kann:

&lt;pre&gt;&lt;code&gt;
typeset -a array
array=( &quot;${(f)$(&lt; dateiname)}&quot; )
&lt;/code&gt;&lt;/pre&gt;

Das funktioniert zwar hervorragend, entfernt aber alle Leerzeichen, die in der Datei vorkommen. So lange man das File nur lesen will ist das in Ordnung, wenn man es aber verarbeiten und die neue Fassung wieder ausgeben möchte, ist das ein K.O-Kriterium. Hier funktioniert dann sowas wie:

&lt;pre&gt;&lt;code&gt;
typeset -a array
&lt; ldap_user_passwd while { read line } { content+=$line$&apos;\n&apos; }
&lt;/code&gt;&lt;/pre&gt;

Die Konstruktion stammt von der zsh-Users Liste, und hat nach einem kurzen Test den Nachteil, dass hier an jede Zeile ein zusätzliches \n angehängt wird. Also:

&lt;pre&gt;&lt;code&gt;
typeset -a array
&lt; ldap_user_passwd while read line
do
  if [[ $array == &quot;&quot; ]] then
   array+=&quot; &quot;
  else
    array+=$line
  fi
done
&lt;/code&gt;&lt;/pre&gt;

Die if-then Geschichte kann man mit der zsh auch nett umgehen:

&lt;pre&gt;&lt;code&gt;
[[ $array == &quot;&quot; ]] &amp;&amp; { array+=&quot; &quot; } || { array+=$line }
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;


Wie gesagt kennt die zsh nicht nur Strings, sondern auch Arrays. Daher werden Strings auch anders verarbeitet. Die Zeichenkette&lt;br /&gt;
string=&quot;Hallo Welt&quot; wird z.B. in einer Schleife nicht in die Elemente &quot;Hallo&quot; und &quot;Welt&quot; zerlegt, wie das bei sh-kompatiblen Shells der Fall ist.&lt;br /&gt;
Erst wenn man das mal verwendet hat um wie schon gesagt zeilenweise Dateien zu verarbeiten, merkt man, wie nützlich das ist.&lt;br /&gt;
Apropos nützlich:

&lt;pre&gt;&lt;code&gt;
for line in $array
do
  [[ $line == *${suchwort}* ]] &amp;&amp; { echo &quot;Suchbegriff gefunden.&quot; }
done
&lt;/code&gt;&lt;/pre&gt;

Find ich genial... :-)&lt;br /&gt;
Und wo wir gerade bei genial sind, hier ein Beispiel für die Positionsparameter:

&lt;pre&gt;&lt;code&gt;
% typeset -a array
% array=( Hallo Welt )
% echo ${array[1]}
Hallo
% echo ${array[2]}
Welt
% echo ${${array[2]}[1]}
W
&lt;/code&gt;&lt;/pre&gt;

More to come. :-)</description>
    <dc:creator>cptsalek</dc:creator>
    <dc:subject>zsh</dc:subject>
    <dc:rights>Copyright &#169; 2007 cptsalek</dc:rights>
    <dc:date>2007-02-27T20:30:00Z</dc:date>
  </item>


<textinput rdf:about="http://cptsalek.twoday.net/search">
   <title>find</title>
   <description>Search this site:</description>
   <name>q</name>
   <link>http://cptsalek.twoday.net/search</link>
</textinput>
<cc:License rdf:about="http://creativecommons.org/licenses/by-nc-sa/2.0/de/">
   <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
   <permits rdf:resource="http://web.resource.org/cc/Distribution" />
   <requires rdf:resource="http://web.resource.org/cc/Notice" />
   <requires rdf:resource="http://web.resource.org/cc/Attribution" />
   <prohibits rdf:resource="http://web.resource.org/cc/CommercialUse" />
   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
   <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
</cc:License>

</rdf:RDF>
