<?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>element - Bash Blog</title>
	<atom:link href="http://blog.kubiii.de/tag/element/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kubiii.de/tag/element/</link>
	<description>Bashscripting Blog</description>
	<lastBuildDate>Fri, 20 May 2016 08:22:08 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>
	<item>
		<title>Arrays</title>
		<link>http://blog.kubiii.de/arrays/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=arrays</link>
					<comments>http://blog.kubiii.de/arrays/#respond</comments>
		
		<dc:creator><![CDATA[Julien]]></dc:creator>
		<pubDate>Fri, 20 May 2016 08:07:21 +0000</pubDate>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[Script Download]]></category>
		<category><![CDATA[arDateien]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[array1.sh]]></category>
		<category><![CDATA[array2.sh]]></category>
		<category><![CDATA[dateiabfrage]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[for-schleife]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[tipps.sh]]></category>
		<category><![CDATA[touch]]></category>
		<category><![CDATA[typeset -r]]></category>
		<category><![CDATA[unset]]></category>
		<guid isPermaLink="false">http://blog.kubiii.de/?p=133</guid>

					<description><![CDATA[<p>Heute soll es um das Thema Arrays im Bashscript gehen. Ein Array ist dabei eine Art besondere Variable/Speicher, welche/r mehrere Strings beinhalten kann. z.B. kann im Array arDateien stehen: datei1 datei2 datei3 und diese möchte man anschließend über eine For-Schleife laufen lassen. Hinweis: Ein Array beginnt bei Index 0 ! array1.sh Ich nutze Arrays gern ...</p>
<p>The post <a href="http://blog.kubiii.de/arrays/">Arrays</a> first appeared on <a href="http://blog.kubiii.de">Bash Blog</a>.</p>
<p>Der Beitrag <a href="http://blog.kubiii.de/arrays/">Arrays</a> erschien zuerst auf <a href="http://blog.kubiii.de">Bash Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Heute soll es um das Thema Arrays im Bashscript gehen.</p>
<p>Ein Array ist dabei eine Art besondere Variable/Speicher, welche/r mehrere Strings beinhalten kann.<br />
z.B. kann im Array <strong><em>arDateien</em></strong> stehen: <strong><em>datei1 datei2 datei3</em></strong> und diese möchte man anschließend über eine For-Schleife laufen lassen.<br />
<strong>Hinweis: Ein Array beginnt bei Index 0 !</strong></p>
<p><em>array1.sh</em></p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

arDateien=(datei1 datei2 datei3)

for datei in ${arDateien&#x5B;*]} ;do
  echo &quot;${datei}&quot;
done

# Ausgabe:
# --------
# datei1
# datei2
# datei3

echo ${arDateien&#x5B;1]}
# Ausgabe: datei2

echo ${arDateien&#x5B;*]}
# Ausgabe: datei1 datei2 datei3
</pre>
<p><br class="clear" /><br />
Ich nutze Arrays gern zur gesammelten Dateiabfrage (z.B. zur Überprüfung, ob alle Dateien erzeugt wurden)</p>
<p><em>array2.sh</em></p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

home=&quot;/home/julien/&quot;

arDateienRW=(&quot;${home}datei1&quot; &quot;${home}datei2&quot; &quot;${home}datei3&quot;)

for datei in arDateienRW&#x5B;*]; do
  echo ${datei}
  touch ${datei}

  if &#x5B; ! -r ${datei} ] || &#x5B; ! -w ${datei} ]; then
    echo &quot;Fehler bei Zugriffsrechten der Datei: \&quot;${datei}\&quot;&quot;
    exit 1
  fi

done
</pre>
<p><br class="clear" /></p>
<p>Nun noch einige nützliche Tipps zu Arrays:</p>
<p><em>tipps.sh</em></p>
<pre class="brush: bash; title: ; notranslate">
# listet alle Werte auf
$ echo &quot;${arDateien&#x5B;*]}&quot;

# listet ebenfalls alle Werte auf
$ echo &quot;${arDateien&#x5B;@]}}&quot;

# gibt der Anzahl der Elemente aus
$ echo &quot;${#arDateien&#x5B;*]}&quot;

# gibt die Länge des entsprechenden Eintrags zurück
$ echo &quot;${#arDateien&#x5B;1]}&quot;

# löschen eines gesamten Arrays
$ unset ${arDateien&#x5B;*]}

# löschen eines Eintrags
$ unset ${arDateien&#x5B;1]}

# kopieren eines gesamten Arrays
$ arDateien_copy=(${arDateien&#x5B;*]})

# Arrayindex belegen
$ arDateien&#x5B;50]=&quot;Inhalt&quot;

# Schreibschutz verwenden
typeset -r arDateien
</pre>
<p>Alle drei Scripte gibt es wie gewohnt hier zum &#8222;Download&#8220;.</p><p>The post <a href="http://blog.kubiii.de/arrays/">Arrays</a> first appeared on <a href="http://blog.kubiii.de">Bash Blog</a>.</p><p>Der Beitrag <a href="http://blog.kubiii.de/arrays/">Arrays</a> erschien zuerst auf <a href="http://blog.kubiii.de">Bash Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://blog.kubiii.de/arrays/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
