<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.avdelning.se/index.php?action=history&amp;feed=atom&amp;title=Variabler_i_whileslingor</id>
	<title>Variabler i whileslingor - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.avdelning.se/index.php?action=history&amp;feed=atom&amp;title=Variabler_i_whileslingor"/>
	<link rel="alternate" type="text/html" href="https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;action=history"/>
	<updated>2026-07-11T04:31:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=387&amp;oldid=prev</id>
		<title>Linadmin: 3 revisions imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=387&amp;oldid=prev"/>
		<updated>2026-05-11T21:53:31Z</updated>

		<summary type="html">&lt;p&gt;3 revisions imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 21:53, 11 May 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Linadmin</name></author>
	</entry>
	<entry>
		<id>https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=386&amp;oldid=prev</id>
		<title>Linuxwiki&gt;Wikiadmin: /* Variabler i whileslingor */</title>
		<link rel="alternate" type="text/html" href="https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=386&amp;oldid=prev"/>
		<updated>2017-05-24T11:22:52Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Variabler i whileslingor&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:22, 24 May 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot;&gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  while read line&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  while read line&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  do&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  do&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      if [[ &quot;$line&quot; == &quot;second line&quot; ]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      if &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;nowiki&amp;gt;&lt;/ins&gt;[[ &quot;$line&quot; == &quot;second line&quot; ]]&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/nowiki&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      then&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      then&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      foo=2&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      foo=2&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Linuxwiki&gt;Wikiadmin</name></author>
	</entry>
	<entry>
		<id>https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=385&amp;oldid=prev</id>
		<title>Linuxwiki&gt;Wikiadmin at 11:22, 24 May 2017</title>
		<link rel="alternate" type="text/html" href="https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=385&amp;oldid=prev"/>
		<updated>2017-05-24T11:22:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:22, 24 May 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l28&quot;&gt;Line 28:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 28:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;x behåller här sitt värde efter whileslingan, dvs i detta fall antalet filer/kataloger i /etc&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;x behåller här sitt värde efter whileslingan, dvs i detta fall antalet filer/kataloger i /etc&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:bash]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Linuxwiki&gt;Wikiadmin</name></author>
	</entry>
	<entry>
		<id>https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=384&amp;oldid=prev</id>
		<title>Linuxwiki&gt;Wikiadmin: Skapade sidan med &#039;== Variabler i whileslingor == Variabler i whileslingor exekveras i ett subshell och kommer inte att bevaras när whileslingan avslutas. Därför kan man använda en &quot;here str...&#039;</title>
		<link rel="alternate" type="text/html" href="https://wiki.avdelning.se/index.php?title=Variabler_i_whileslingor&amp;diff=384&amp;oldid=prev"/>
		<updated>2017-05-24T11:21:35Z</updated>

		<summary type="html">&lt;p&gt;Skapade sidan med &amp;#039;== Variabler i whileslingor == Variabler i whileslingor exekveras i ett subshell och kommer inte att bevaras när whileslingan avslutas. Därför kan man använda en &amp;quot;here str...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Variabler i whileslingor ==&lt;br /&gt;
Variabler i whileslingor exekveras i ett subshell och kommer inte att bevaras när whileslingan avslutas. Därför kan man använda en &amp;quot;here string&amp;quot; där bara en del exekveras i ett subshell.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Normalt&amp;#039;&amp;#039; ser en whileslinga ut t ex så här:&lt;br /&gt;
 echo -e $lines | while read line &lt;br /&gt;
 ...&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
Genom att flytta det initiala kommandot, &amp;quot;echo -e $lines&amp;quot; i detta fall, efter &amp;#039;&amp;#039;&amp;#039;done&amp;#039;&amp;#039;&amp;#039; och föregå det med &amp;#039;&amp;#039;&amp;#039;&amp;lt;&amp;lt;&amp;lt;&amp;#039;&amp;#039;&amp;#039; exekveras enbart &amp;quot;echo -e $lines&amp;quot; i ett subshell. Den färdiga koden ser då ut så här (variabeln $foo behåller nu sitt värde efter whileslingan):&lt;br /&gt;
&lt;br /&gt;
 while read line&lt;br /&gt;
 do&lt;br /&gt;
     if [[ &amp;quot;$line&amp;quot; == &amp;quot;second line&amp;quot; ]]&lt;br /&gt;
     then&lt;br /&gt;
     foo=2&lt;br /&gt;
     echo &amp;quot;Variable \$foo updated to $foo inside if inside while loop&amp;quot;&lt;br /&gt;
     fi&lt;br /&gt;
     echo &amp;quot;Value of \$foo in while loop body: $foo&amp;quot;&lt;br /&gt;
 done &amp;#039;&amp;#039;&amp;#039;&amp;lt;&amp;lt;&amp;lt; &amp;quot;$(echo -e &amp;quot;$lines&amp;quot;)&amp;quot;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Ett annat exempel:&lt;br /&gt;
 x=0&lt;br /&gt;
 while read v&lt;br /&gt;
 do&lt;br /&gt;
    x=$(( $x + 1 ))&lt;br /&gt;
 done &amp;#039;&amp;#039;&amp;#039;&amp;lt;&amp;lt;&amp;lt; &amp;quot;$(ls -d /etc)&amp;quot;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
x behåller här sitt värde efter whileslingan, dvs i detta fall antalet filer/kataloger i /etc&lt;/div&gt;</summary>
		<author><name>Linuxwiki&gt;Wikiadmin</name></author>
	</entry>
</feed>