<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Abraxas &#187; dash</title>
	<atom:link href="http://www.effinger.org/blog/tag/dash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.effinger.org/blog</link>
	<description>a personal knowledge base</description>
	<lastBuildDate>Mon, 23 Jan 2012 22:05:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Dash Shell Scripting &#8211; Mit Arrays arbeiten</title>
		<link>http://www.effinger.org/blog/2008/11/20/dash-shell-scripting-mit-arrays-arbeiten/</link>
		<comments>http://www.effinger.org/blog/2008/11/20/dash-shell-scripting-mit-arrays-arbeiten/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 21:03:46 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[dash]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=221</guid>
		<description><![CDATA[<p>Bei der Bourne-Shell ist es ohne Probleme möglich verschiedenste Dinge mit Arrays anzustellen. Viele interessante und lehrreiche Beispiele finden sich im Unix Bash Scripting Blog. Allerdings verwendet Ubuntu für Scripts mittlerweile die dash, die zwar nicht den Funktionsumfang der Bash bereitstellt, aber dafür dem POSIX-Standard entspricht und schneller sein soll. Leider kann man damit nicht [...]]]></description>
			<content:encoded><![CDATA[<p>Bei der Bourne-Shell ist es ohne Probleme möglich verschiedenste Dinge mit Arrays anzustellen. Viele interessante und lehrreiche Beispiele finden sich im <a href="http://unstableme.blogspot.com/2008/06/using-array-in-bash-script.html">Unix Bash Scripting Blog</a>. Allerdings verwendet Ubuntu für Scripts mittlerweile die dash, die zwar nicht den Funktionsumfang der Bash bereitstellt, aber dafür dem POSIX-Standard entspricht und schneller sein soll. Leider kann man damit nicht wie von der Bash gewohnt mit Arrays arbeiten. Wie kann man sich nun behelfen? Ich wollte für mein Beispiel zwei Arrays (TAPS, ARP_IPS) so kombinieren, dass jeweils die zusammengehörigen Parameter (gleicher Index im Array) ausgegeben werden. So habe ich es hinbekommen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">TAPS</span>=<span style="color: #ff0000;">&quot;tap0 tap1 tap2&quot;</span>
<span style="color: #007800;">ARP_IPS</span>=<span style="color: #ff0000;">&quot;169.254.0.1/32 169.254.0.2/32 169.254.0.3/32&quot;</span>
<span style="color: #007800;">i</span>=<span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">for</span> TAP <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$TAPS</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">j</span>=<span style="color: #000000;">0</span>
  <span style="color: #000000; font-weight: bold;">for</span> ARP_IP <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$ARP_IPS</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$i</span> = <span style="color: #007800;">$j</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #7a0874; font-weight: bold;">break</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #007800;">j</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$j</span> + <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">done</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$TAP</span> <span style="color: #007800;">$ARP_IP</span>
  <span style="color: #007800;">i</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$i</span> + <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Als Ausgabe des Scripts erhält man folgendes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">tap0 169.254.0.1<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>
tap1 169.254.0.2<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span>
tap2 169.254.0.3<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2008/11/20/dash-shell-scripting-mit-arrays-arbeiten/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

