<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>https://www.binefa.com/index.php?action=history&amp;feed=atom&amp;title=Teoria_Bash_01%3A_Rep%C3%A0s_i_Funcions</id>
	<title>Teoria Bash 01: Repàs i Funcions - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="https://www.binefa.com/index.php?action=history&amp;feed=atom&amp;title=Teoria_Bash_01%3A_Rep%C3%A0s_i_Funcions"/>
	<link rel="alternate" type="text/html" href="https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;action=history"/>
	<updated>2026-05-03T21:22:18Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11630&amp;oldid=prev</id>
		<title>Jordi Binefa: /* Teoria Bash 01: Repàs i Funcions */</title>
		<link rel="alternate" type="text/html" href="https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11630&amp;oldid=prev"/>
		<updated>2026-01-29T11:34:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Teoria Bash 01: Repàs i Funcions&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&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;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 11:34, 29 gen 2026&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-l1&quot; &gt;Línia 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;= Teoria Bash 01: Repàs i Funcions =&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;= Teoria Bash 01: Repàs i Funcions =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;== 0. ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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;== 0. &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Ordres noves i document en html &lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;* Ordres noves: [https://www.tutorialspoint.com/unix_commands/local.htm local], [https://www.geeksforgeeks.org/linux-unix/shell-scripting-readonly-command/ readonly], [https://www.geeksforgeeks.org/linux-unix/tee-command-linux-example/ tee], [https://www.geeksforgeeks.org/linux-unix/basename-command-in-linux-with-examples/ basename] i [https://www.geeksforgeeks.org/linux-unix/shift-command-in-linux-with-examples/ shift])&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;* Ordres noves: [https://www.tutorialspoint.com/unix_commands/local.htm local], [https://www.geeksforgeeks.org/linux-unix/shell-scripting-readonly-command/ readonly], [https://www.geeksforgeeks.org/linux-unix/tee-command-linux-example/ tee], [https://www.geeksforgeeks.org/linux-unix/basename-command-in-linux-with-examples/ basename] i [https://www.geeksforgeeks.org/linux-unix/shift-command-in-linux-with-examples/ shift])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;* [https://binefa.com/asix2/pj6/bash/teoriaBash01.html Aquest document en html]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;* [https://binefa.com/asix2/pj6/bash/teoriaBash01.html Aquest document en html]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki_binefa_com:diff::1.12:old-11629:rev-11630 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jordi Binefa</name></author>
		
	</entry>
	<entry>
		<id>https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11629&amp;oldid=prev</id>
		<title>Jordi Binefa a 11:33, 29 gen 2026</title>
		<link rel="alternate" type="text/html" href="https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11629&amp;oldid=prev"/>
		<updated>2026-01-29T11:33:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&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;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 11:33, 29 gen 2026&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-l1&quot; &gt;Línia 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;= Teoria Bash 01: Repàs i Funcions =&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;= Teoria Bash 01: Repàs i Funcions =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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;== 0. ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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;* Ordres noves: [https://www.tutorialspoint.com/unix_commands/local.htm local], [https://www.geeksforgeeks.org/linux-unix/shell-scripting-readonly-command/ readonly], [https://www.geeksforgeeks.org/linux-unix/tee-command-linux-example/ tee], [https://www.geeksforgeeks.org/linux-unix/basename-command-in-linux-with-examples/ basename] i [https://www.geeksforgeeks.org/linux-unix/shift-command-in-linux-with-examples/ shift])&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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;* [https://binefa.com/asix2/pj6/bash/teoriaBash01.html Aquest document en html]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;== 1. Repàs de conceptes bàsics ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;== 1. Repàs de conceptes bàsics ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki_binefa_com:diff::1.12:old-11627:rev-11629 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jordi Binefa</name></author>
		
	</entry>
	<entry>
		<id>https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11627&amp;oldid=prev</id>
		<title>Jordi Binefa: /* 5. Consells i bones pràctiques */</title>
		<link rel="alternate" type="text/html" href="https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11627&amp;oldid=prev"/>
		<updated>2026-01-29T11:29:32Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;5. Consells i bones pràctiques&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&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;ca&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Versió més antiga&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revisió del 11:29, 29 gen 2026&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-l417&quot; &gt;Línia 417:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Línia 417:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;== 5. Consells i bones pràctiques ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;== 5. Consells i bones pràctiques ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;1. &lt;/del&gt;'''Sempre usar '''''INLINE''CODE''4'''''''' per a variables dins de funcions&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Sempre usar '''''INLINE''CODE''4'''''''' per a variables dins de funcions&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;2. &lt;/del&gt;'''Validar paràmetres''' abans de processar-los&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Validar paràmetres''' abans de processar-los&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;3. &lt;/del&gt;'''Retornar codis d'error significatius''' (0 = èxit, &amp;gt;0 = error)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Retornar codis d'error significatius''' (0 = èxit, &amp;gt;0 = error)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;4. &lt;/del&gt;'''Documentar les funcions''' amb comentaris&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Documentar les funcions''' amb comentaris&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;5. &lt;/del&gt;'''Usar noms descriptius''' per a funcions i variables&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Usar noms descriptius''' per a funcions i variables&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;6. &lt;/del&gt;'''Evitar efectes secundaris''' quan sigui possible&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Evitar efectes secundaris''' quan sigui possible&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; 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;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;7. &lt;/del&gt;'''Una funció, una tasca''' (principi de responsabilitat única)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; 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 class=&quot;diffchange diffchange-inline&quot;&gt;* &lt;/ins&gt;'''Una funció, una tasca''' (principi de responsabilitat única)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;== Resum ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; 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;== Resum ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki_binefa_com:diff::1.12:old-11626:rev-11627 --&gt;
&lt;/table&gt;</summary>
		<author><name>Jordi Binefa</name></author>
		
	</entry>
	<entry>
		<id>https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11626&amp;oldid=prev</id>
		<title>Jordi Binefa: Es crea la pàgina amb «= Teoria Bash 01: Repàs i Funcions =  == 1. Repàs de conceptes bàsics ==  === Variables ===   # Assignació (sense espais!)  nom=&amp;quot;Joan&amp;quot;  edat=25    # Ús...».</title>
		<link rel="alternate" type="text/html" href="https://www.binefa.com/index.php?title=Teoria_Bash_01:_Rep%C3%A0s_i_Funcions&amp;diff=11626&amp;oldid=prev"/>
		<updated>2026-01-29T11:28:31Z</updated>

		<summary type="html">&lt;p&gt;Es crea la pàgina amb «= Teoria Bash 01: Repàs i Funcions =  == 1. Repàs de conceptes bàsics ==  === Variables ===   # Assignació (sense espais!)  nom=&amp;quot;Joan&amp;quot;  edat=25    # Ús...».&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Teoria Bash 01: Repàs i Funcions =&lt;br /&gt;
&lt;br /&gt;
== 1. Repàs de conceptes bàsics ==&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
 # Assignació (sense espais!)&lt;br /&gt;
 nom=&amp;amp;quot;Joan&amp;amp;quot;&lt;br /&gt;
 edat=25&lt;br /&gt;
 &lt;br /&gt;
 # Ús de variables&lt;br /&gt;
 echo &amp;amp;quot;Hola $nom&amp;amp;quot;&lt;br /&gt;
 echo &amp;amp;quot;Tens ${edat} anys&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Variables d&amp;amp;#039;entorn&lt;br /&gt;
 export PATH=&amp;amp;quot;/usr/local/bin:$PATH&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 # Llegir input de l&amp;amp;#039;usuari&lt;br /&gt;
 read -p &amp;amp;quot;Introdueix el teu nom: &amp;amp;quot; nom&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Condicionals ===&lt;br /&gt;
&lt;br /&gt;
 # Sintaxi bàsica&lt;br /&gt;
 if [ condició ]; then&lt;br /&gt;
     # codi&lt;br /&gt;
 elif [ altra_condició ]; then&lt;br /&gt;
     # altre codi&lt;br /&gt;
 else&lt;br /&gt;
     # codi alternatiu&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Operadors de comparació numèrica&lt;br /&gt;
 # -eq (igual), -ne (diferent), -lt (menor), -le (menor o igual)&lt;br /&gt;
 # -gt (major), -ge (major o igual)&lt;br /&gt;
 &lt;br /&gt;
 if [ $edat -ge 18 ]; then&lt;br /&gt;
     echo &amp;amp;quot;Ets major d&amp;amp;#039;edat&amp;amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Operadors de comparació de strings&lt;br /&gt;
 # = (igual), != (diferent), -z (buit), -n (no buit)&lt;br /&gt;
 &lt;br /&gt;
 if [ &amp;amp;quot;$nom&amp;amp;quot; = &amp;amp;quot;Joan&amp;amp;quot; ]; then&lt;br /&gt;
     echo &amp;amp;quot;Hola Joan!&amp;amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Operadors de fitxers&lt;br /&gt;
 # -f (fitxer existeix), -d (directori existeix)&lt;br /&gt;
 # -r (llegible), -w (escrivible), -x (executable)&lt;br /&gt;
 &lt;br /&gt;
 if [ -f &amp;amp;quot;/etc/passwd&amp;amp;quot; ]; then&lt;br /&gt;
     echo &amp;amp;quot;El fitxer existeix&amp;amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # Operadors lògics&lt;br /&gt;
 # -a (AND), -o (OR), ! (NOT)&lt;br /&gt;
 # També es pot usar &amp;amp;amp;&amp;amp;amp; i ||&lt;br /&gt;
 &lt;br /&gt;
 if [ $edat -ge 18 ] &amp;amp;amp;&amp;amp;amp; [ &amp;amp;quot;$nom&amp;amp;quot; != &amp;amp;quot;&amp;amp;quot; ]; then&lt;br /&gt;
     echo &amp;amp;quot;Dades vàlides&amp;amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Bucles ===&lt;br /&gt;
&lt;br /&gt;
 # Bucle for amb llista&lt;br /&gt;
 for nom in Joan Maria Pere; do&lt;br /&gt;
     echo &amp;amp;quot;Hola $nom&amp;amp;quot;&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 # Bucle for amb rang&lt;br /&gt;
 for i in {1..10}; do&lt;br /&gt;
     echo &amp;amp;quot;Número $i&amp;amp;quot;&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 # Bucle for estil C&lt;br /&gt;
 for ((i=0; i&amp;amp;lt;10; i++)); do&lt;br /&gt;
     echo &amp;amp;quot;Comptador: $i&amp;amp;quot;&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 # Bucle while&lt;br /&gt;
 contador=0&lt;br /&gt;
 while [ $contador -lt 5 ]; do&lt;br /&gt;
     echo &amp;amp;quot;Valor: $contador&amp;amp;quot;&lt;br /&gt;
     ((contador++))&lt;br /&gt;
 done&lt;br /&gt;
 &lt;br /&gt;
 # Llegir fitxer línia per línia&lt;br /&gt;
 while IFS= read -r linia; do&lt;br /&gt;
     echo &amp;amp;quot;Línia: $linia&amp;amp;quot;&lt;br /&gt;
 done &amp;amp;lt; fitxer.txt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 2. Funcions en Bash ==&lt;br /&gt;
&lt;br /&gt;
=== Definició de funcions ===&lt;br /&gt;
&lt;br /&gt;
Hi ha dues sintaxis per definir funcions:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Sintaxi 1 (més comuna)&lt;br /&gt;
 nom_funcio() {&lt;br /&gt;
     # codi de la funció&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Sintaxi 2&lt;br /&gt;
 function nom_funcio {&lt;br /&gt;
     # codi de la funció&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Exemple bàsic ===&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 &lt;br /&gt;
 saludar() {&lt;br /&gt;
     echo &amp;amp;quot;Hola des de la funció!&amp;amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Cridar la funció&lt;br /&gt;
 saludar&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Paràmetres de funcions ===&lt;br /&gt;
&lt;br /&gt;
Les funcions reben paràmetres igual que els scripts:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 saludar() {&lt;br /&gt;
     echo &amp;amp;quot;Hola $1!&amp;amp;quot;&lt;br /&gt;
     echo &amp;amp;quot;Tens $2 anys&amp;amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Cridar amb paràmetres&lt;br /&gt;
 saludar &amp;amp;quot;Joan&amp;amp;quot; 25&lt;br /&gt;
 &lt;br /&gt;
 # Variables especials per a paràmetres:&lt;br /&gt;
 # $1, $2, $3... - paràmetres individuals&lt;br /&gt;
 # $@ - tots els paràmetres com a paraules separades&lt;br /&gt;
 # $* - tots els paràmetres com a una sola cadena&lt;br /&gt;
 # $# - nombre de paràmetres&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Exemple amb múltiples paràmetres ===&lt;br /&gt;
&lt;br /&gt;
 mostrar_info() {&lt;br /&gt;
     echo &amp;amp;quot;Nombre de paràmetres: $#&amp;amp;quot;&lt;br /&gt;
     echo &amp;amp;quot;Primer paràmetre: $1&amp;amp;quot;&lt;br /&gt;
     echo &amp;amp;quot;Segon paràmetre: $2&amp;amp;quot;&lt;br /&gt;
     echo &amp;amp;quot;Tots els paràmetres: $@&amp;amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 mostrar_info un dos tres quatre&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Retornar valors ===&lt;br /&gt;
&lt;br /&gt;
En Bash, les funcions no retornen valors com en altres llenguatges. Hi ha dues maneres principals:&lt;br /&gt;
&lt;br /&gt;
==== 1. Usar '''''INLINE''CODE''0''''' (només per a codis d'estat 0-255) ====&lt;br /&gt;
&lt;br /&gt;
 es_parell() {&lt;br /&gt;
     local num=$1&lt;br /&gt;
     if [ $((num % 2)) -eq 0 ]; then&lt;br /&gt;
         return 0  # èxit (true)&lt;br /&gt;
     else&lt;br /&gt;
         return 1  # error (false)&lt;br /&gt;
     fi&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Comprovar el resultat&lt;br /&gt;
 if es_parell 4; then&lt;br /&gt;
     echo &amp;amp;quot;4 és parell&amp;amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
 &lt;br /&gt;
 # O capturar el codi de retorn&lt;br /&gt;
 es_parell 5&lt;br /&gt;
 resultat=$?&lt;br /&gt;
 echo &amp;amp;quot;Codi de retorn: $resultat&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== 2. Usar '''''INLINE''CODE''1''''' (per retornar dades) ====&lt;br /&gt;
&lt;br /&gt;
 sumar() {&lt;br /&gt;
     local a=$1&lt;br /&gt;
     local b=$2&lt;br /&gt;
     local suma=$((a + b))&lt;br /&gt;
     echo $suma&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Capturar el resultat amb $()&lt;br /&gt;
 resultat=$(sumar 5 3)&lt;br /&gt;
 echo &amp;amp;quot;La suma és: $resultat&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Scope de variables: '''''INLINE''CODE''2''''' vs global ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Variable global&lt;br /&gt;
 variable_global=&amp;amp;quot;Sóc global&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 funcio_exemple() {&lt;br /&gt;
     # Variable local (només visible dins la funció)&lt;br /&gt;
     local variable_local=&amp;amp;quot;Sóc local&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
     # Modificar variable global&lt;br /&gt;
     variable_global=&amp;amp;quot;He estat modificada&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
     echo &amp;amp;quot;Dins la funció:&amp;amp;quot;&lt;br /&gt;
     echo &amp;amp;quot;  Global: $variable_global&amp;amp;quot;&lt;br /&gt;
     echo &amp;amp;quot;  Local: $variable_local&amp;amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 funcio_exemple&lt;br /&gt;
 &lt;br /&gt;
 echo &amp;amp;quot;Fora de la funció:&amp;amp;quot;&lt;br /&gt;
 echo &amp;amp;quot;  Global: $variable_global&amp;amp;quot;&lt;br /&gt;
 echo &amp;amp;quot;  Local: $variable_local&amp;amp;quot;  # Estarà buida!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Bones pràctiques:'''&lt;br /&gt;
* Sempre usar '''''INLINE''CODE''3''''' per a variables dins de funcions&lt;br /&gt;
* Només usar variables globals quan calgui compartir estat&lt;br /&gt;
* Noms descriptius per a les funcions&lt;br /&gt;
&lt;br /&gt;
=== Exemple complet d'una funció útil ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 &lt;br /&gt;
 # Funció que comprova si un fitxer existeix i és llegible&lt;br /&gt;
 comprovar_fitxer() {&lt;br /&gt;
     local fitxer=$1&lt;br /&gt;
 &lt;br /&gt;
     if [ -z &amp;amp;quot;$fitxer&amp;amp;quot; ]; then&lt;br /&gt;
         echo &amp;amp;quot;Error: Cal especificar un fitxer&amp;amp;quot;&lt;br /&gt;
         return 1&lt;br /&gt;
     fi&lt;br /&gt;
 &lt;br /&gt;
     if [ ! -f &amp;amp;quot;$fitxer&amp;amp;quot; ]; then&lt;br /&gt;
         echo &amp;amp;quot;Error: El fitxer $fitxer no existeix&amp;amp;quot;&lt;br /&gt;
         return 2&lt;br /&gt;
     fi&lt;br /&gt;
 &lt;br /&gt;
     if [ ! -r &amp;amp;quot;$fitxer&amp;amp;quot; ]; then&lt;br /&gt;
         echo &amp;amp;quot;Error: El fitxer $fitxer no és llegible&amp;amp;quot;&lt;br /&gt;
         return 3&lt;br /&gt;
     fi&lt;br /&gt;
 &lt;br /&gt;
     echo &amp;amp;quot;El fitxer $fitxer és vàlid&amp;amp;quot;&lt;br /&gt;
     return 0&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Exemple d&amp;amp;#039;ús&lt;br /&gt;
 comprovar_fitxer &amp;amp;quot;/etc/passwd&amp;amp;quot;&lt;br /&gt;
 echo &amp;amp;quot;Codi de retorn: $?&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 comprovar''fitxer &amp;amp;quot;/fitxer''inexistent&amp;amp;quot;&lt;br /&gt;
 echo &amp;amp;quot;Codi de retorn: $?&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Funcions amb validació de paràmetres ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 dividir() {&lt;br /&gt;
     # Comprovar que tenim 2 paràmetres&lt;br /&gt;
     if [ $# -ne 2 ]; then&lt;br /&gt;
         echo &amp;amp;quot;Error: Cal proporcionar exactament 2 números&amp;amp;quot;&lt;br /&gt;
         return 1&lt;br /&gt;
     fi&lt;br /&gt;
 &lt;br /&gt;
     local dividend=$1&lt;br /&gt;
     local divisor=$2&lt;br /&gt;
 &lt;br /&gt;
     # Comprovar divisió per zero&lt;br /&gt;
     if [ $divisor -eq 0 ]; then&lt;br /&gt;
         echo &amp;amp;quot;Error: No es pot dividir per zero&amp;amp;quot;&lt;br /&gt;
         return 2&lt;br /&gt;
     fi&lt;br /&gt;
 &lt;br /&gt;
     # Fer la divisió&lt;br /&gt;
     local resultat=$((dividend / divisor))&lt;br /&gt;
     echo $resultat&lt;br /&gt;
     return 0&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Ús&lt;br /&gt;
 resultat=$(dividir 10 2)&lt;br /&gt;
 if [ $? -eq 0 ]; then&lt;br /&gt;
     echo &amp;amp;quot;Resultat: $resultat&amp;amp;quot;&lt;br /&gt;
 fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 3. Organització del codi amb funcions ==&lt;br /&gt;
&lt;br /&gt;
=== Estructura recomanada d'un script ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 &lt;br /&gt;
 #############################################&lt;br /&gt;
 # Script: exemple.sh&lt;br /&gt;
 # Descripció: Exemple d&amp;amp;#039;estructura de script&lt;br /&gt;
 # Autor: El teu nom&lt;br /&gt;
 # Data: 2024-01-08&lt;br /&gt;
 #############################################&lt;br /&gt;
 &lt;br /&gt;
 # Variables globals&lt;br /&gt;
 readonly SCRIPT''DIR=&amp;amp;quot;$(cd &amp;amp;quot;$(dirname &amp;amp;quot;${BASH''SOURCE[0]}&amp;amp;quot;)&amp;amp;quot; &amp;amp;amp;&amp;amp;amp; pwd)&amp;amp;quot;&lt;br /&gt;
 readonly LOG_FILE=&amp;amp;quot;/var/log/script.log&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 #############################################&lt;br /&gt;
 # Funcions auxiliars&lt;br /&gt;
 #############################################&lt;br /&gt;
 &lt;br /&gt;
 mostrar_ajuda() {&lt;br /&gt;
     cat &amp;amp;lt;&amp;amp;lt; EOF&lt;br /&gt;
 Ús: $(basename $0) [opcions]&lt;br /&gt;
 &lt;br /&gt;
 Opcions:&lt;br /&gt;
     -h, --help      Mostra aquesta ajuda&lt;br /&gt;
     -v, --verbose   Mode verbós&lt;br /&gt;
     -f FITXER       Especifica un fitxer&lt;br /&gt;
 EOF&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 log() {&lt;br /&gt;
     local missatge=$1&lt;br /&gt;
     echo &amp;amp;quot;[$(date &amp;amp;#039;+%Y-%m-%d %H:%M:%S&amp;amp;#039;)] $missatge&amp;amp;quot; | tee -a &amp;amp;quot;$LOG_FILE&amp;amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 #############################################&lt;br /&gt;
 # Funcions principals&lt;br /&gt;
 #############################################&lt;br /&gt;
 &lt;br /&gt;
 processar_dades() {&lt;br /&gt;
     local fitxer=$1&lt;br /&gt;
     log &amp;amp;quot;Processant $fitxer...&amp;amp;quot;&lt;br /&gt;
     # Codi de processament aquí&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 #############################################&lt;br /&gt;
 # Programa principal&lt;br /&gt;
 #############################################&lt;br /&gt;
 &lt;br /&gt;
 main() {&lt;br /&gt;
     # Comprovar arguments&lt;br /&gt;
     if [ $# -eq 0 ]; then&lt;br /&gt;
         mostrar_ajuda&lt;br /&gt;
         exit 1&lt;br /&gt;
     fi&lt;br /&gt;
 &lt;br /&gt;
     # Processar opcions&lt;br /&gt;
     while [ $# -gt 0 ]; do&lt;br /&gt;
         case $1 in&lt;br /&gt;
             -h|--help)&lt;br /&gt;
                 mostrar_ajuda&lt;br /&gt;
                 exit 0&lt;br /&gt;
                 ;;&lt;br /&gt;
             -f)&lt;br /&gt;
                 processar_dades &amp;amp;quot;$2&amp;amp;quot;&lt;br /&gt;
                 shift 2&lt;br /&gt;
                 ;;&lt;br /&gt;
             *)&lt;br /&gt;
                 echo &amp;amp;quot;Opció desconeguda: $1&amp;amp;quot;&lt;br /&gt;
                 mostrar_ajuda&lt;br /&gt;
                 exit 1&lt;br /&gt;
                 ;;&lt;br /&gt;
         esac&lt;br /&gt;
     done&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # Executar programa principal&lt;br /&gt;
 main &amp;amp;quot;$@&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 4. Ús de colors al terminal ==&lt;br /&gt;
&lt;br /&gt;
=== Exemple d'ús de colors ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 # Definició de colors (ANSI)&lt;br /&gt;
 readonly CL_VERD=&amp;amp;#039;\033[0;32m&amp;amp;#039;&lt;br /&gt;
 readonly CL_VERMELL=&amp;amp;#039;\033[0;31m&amp;amp;#039;&lt;br /&gt;
 readonly CL_GROC=&amp;amp;#039;\033[0;33m&amp;amp;#039;&lt;br /&gt;
 readonly CL_RESET=&amp;amp;#039;\033[0m&amp;amp;#039; # Torna al color normal&lt;br /&gt;
 readonly LOG_FILE=&amp;amp;quot;nouLog.log&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 log() {&lt;br /&gt;
     local nivell=$1&lt;br /&gt;
     local missatge=$2&lt;br /&gt;
     local data=$(date &amp;amp;#039;+%Y-%m-%d %H:%M:%S&amp;amp;#039;)&lt;br /&gt;
     local color=&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
     # Escollir color segons el nivell&lt;br /&gt;
     case &amp;amp;quot;$nivell&amp;amp;quot; in&lt;br /&gt;
         &amp;amp;quot;INFO&amp;amp;quot;)  color=$CL_VERD ;;&lt;br /&gt;
         &amp;amp;quot;ERROR&amp;amp;quot;) color=$CL_VERMELL ;;&lt;br /&gt;
         &amp;amp;quot;WARN&amp;amp;quot;)  color=$CL_GROC ;;&lt;br /&gt;
         *)       color=$CL_RESET ;;&lt;br /&gt;
     esac&lt;br /&gt;
 &lt;br /&gt;
     # 1. Imprimir a la pantalla AMB colors&lt;br /&gt;
     echo -e &amp;amp;quot;${color}[$data] [$nivell] $missatge${CL_RESET}&amp;amp;quot;&lt;br /&gt;
 &lt;br /&gt;
     # 2. Guardar al fitxer SENSE colors (perquè sigui llegible amb qualsevol editor)&lt;br /&gt;
     echo &amp;amp;quot;[$data] [$nivell] $missatge&amp;amp;quot; &amp;amp;gt;&amp;amp;gt; &amp;amp;quot;$LOG_FILE&amp;amp;quot;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 # --- Mock de funcionament ---&lt;br /&gt;
 log &amp;amp;quot;INFO&amp;amp;quot; &amp;amp;quot;El sistema s&amp;amp;#039;ha iniciat correctament.&amp;amp;quot;&lt;br /&gt;
 log &amp;amp;quot;WARN&amp;amp;quot; &amp;amp;quot;L&amp;amp;#039;espai de disc és inferior al 10%.&amp;amp;quot;&lt;br /&gt;
 log &amp;amp;quot;ERROR&amp;amp;quot; &amp;amp;quot;No s&amp;amp;#039;ha pogut escriure al directori de destí.&amp;amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 5. Consells i bones pràctiques ==&lt;br /&gt;
&lt;br /&gt;
1. '''Sempre usar '''''INLINE''CODE''4'''''''' per a variables dins de funcions&lt;br /&gt;
2. '''Validar paràmetres''' abans de processar-los&lt;br /&gt;
3. '''Retornar codis d'error significatius''' (0 = èxit, &amp;gt;0 = error)&lt;br /&gt;
4. '''Documentar les funcions''' amb comentaris&lt;br /&gt;
5. '''Usar noms descriptius''' per a funcions i variables&lt;br /&gt;
6. '''Evitar efectes secundaris''' quan sigui possible&lt;br /&gt;
7. '''Una funció, una tasca''' (principi de responsabilitat única)&lt;br /&gt;
&lt;br /&gt;
== Resum ==&lt;br /&gt;
&lt;br /&gt;
* Les funcions organitzen el codi en blocs reutilitzables&lt;br /&gt;
* Reben paràmetres amb '''''INLINE''CODE''5''''', '''''INLINE''CODE''6''''', etc.&lt;br /&gt;
* Retornen codis amb '''''INLINE''CODE''7''''' (0-255)&lt;br /&gt;
* Retornen dades amb '''''INLINE''CODE''8''''' i captura amb '''''INLINE''CODE''9'''''&lt;br /&gt;
* Usar '''''INLINE''CODE''10''''' per a variables dins de funcions&lt;br /&gt;
* Sempre validar paràmetres i gestionar errors&lt;/div&gt;</summary>
		<author><name>Jordi Binefa</name></author>
		
	</entry>
</feed>