<?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>piouPiouM&#039;s dev&#187; Archives pour le tag shell – piouPiouM&#039;s dev</title>
	<atom:link href="http://pioupioum.fr/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d&#039;un développeur web</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:47:44 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bash&#160;: convertir un string en entier</title>
		<link>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html</link>
		<comments>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html#comments</comments>
		<pubDate>Sat, 06 Mar 2010 19:06:25 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[convertir]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=340</guid>
		<description><![CDATA[Bash n&#8217;offre pas de fonction pour convertir une chaîne de caractères ou un nombre flottant en un entier.
Cela n&#8217;est toute fois pas impossible, il suffit de faire appel à printf1 et le tour est joué&#160;!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
# string_to_int.sh - Shell script to convert a string or float number
# to an integer.
&#160;
function string_to_int &#40;&#41;
&#123;
    [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><a href="http://fr.wikipedia.org/wiki/Bourne-Again_shell" title="Bourne-Again shell - Wikipédia">Bash</a> n&#8217;offre pas de fonction pour convertir une chaîne de caractères ou un nombre flottant en un entier.<br />
Cela n&#8217;est toute fois pas impossible, il suffit de faire appel à <code>printf</code><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> et le tour est joué&#160;!</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/env bash</span>
<span style="color: #666666; font-style: italic;"># string_to_int.sh - Shell script to convert a string or float number</span>
<span style="color: #666666; font-style: italic;"># to an integer.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> string_to_int <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">LANG</span>=C
    <span style="color: #007800;">d</span>=<span style="color: #800000;">${1##*.}</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${#1}</span> <span style="color: #660033;">-eq</span> <span style="color: #800000;">${#d}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">d</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #007800;">e</span>=<span style="color: #800000;">${1%.*}</span>
    <span style="color: #007800;">e</span>=<span style="color: #800000;">${e//,/}</span>
    <span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #000000; font-weight: bold;">%</span>.0f <span style="color: #ff0000;">&quot;<span style="color: #007800;">$e</span>.<span style="color: #007800;">$d</span>&quot;</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">not_int</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;12.652&quot;</span> <span style="color: #ff0000;">&quot;-12.652&quot;</span> <span style="color: #000000;">12.652</span> <span style="color: #000000;">14</span> <span style="color: #ff0000;">&quot;12,652&quot;</span> foo <span style="color: #ff0000;">&quot;1,254.8&quot;</span> <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> <span style="color: #ff0000;">&quot;125,160,254.8&quot;</span> <span style="color: #ff0000;">&quot;125,160,254&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> value <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${not_int[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Convert <span style="color: #007800;">$value</span> to int: <span style="color: #007800;">$(string_to_int $value)</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>


<p>Ce qui nous donne&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>string_to_int.sh 
Convert <span style="color: #000000;">12.652</span> to int: <span style="color: #000000;">13</span>
Convert -<span style="color: #000000;">12.652</span> to int: <span style="color: #660033;">-13</span>
Convert <span style="color: #000000;">12.652</span> to int: <span style="color: #000000;">13</span>
Convert <span style="color: #000000;">14</span> to int: <span style="color: #000000;">14</span>
Convert <span style="color: #000000;">12</span>,<span style="color: #000000;">652</span> to int: <span style="color: #000000;">12652</span>
Convert foo to int: <span style="color: #000000;">0</span>
Convert <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">1255</span>
Convert <span style="color: #000000;">1</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">1255</span>
Convert <span style="color: #000000;">125</span>,<span style="color: #000000;">160</span>,<span style="color: #000000;">254.8</span> to int: <span style="color: #000000;">125160255</span>
Convert <span style="color: #000000;">125</span>,<span style="color: #000000;">160</span>,<span style="color: #000000;">254</span> to int: <span style="color: #000000;">125160254</span></pre></div></div>


<p>Voir <a href="http://gist.github.com/324313">sur Github</a>.</p>

<p><strong>Mis à jour le 7 mars 2010</strong><br />
Prise en charge de la notation US. Merci à <a href="http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html#comment-1159">patpro</a>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li><li><a href='http://pioupioum.fr/snippets/convertir-icone-icns-png.html' title='Convertir une icône ICNS en une image PNG'>Convertir une icône ICNS en une image PNG</a></li><li><a href='http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html' title='Rechercher le nom réel d&#8217;un utilisateur sous Leopard'>Rechercher le nom réel d&#8217;un utilisateur sous Leopard</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>une substitution du séparateur des décimals <code>.</code> en <code>,</code> est nécessaire avant de faire appel à <code>printf</code>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Convertir une icône ICNS en une image PNG</title>
		<link>http://pioupioum.fr/snippets/convertir-icone-icns-png.html</link>
		<comments>http://pioupioum.fr/snippets/convertir-icone-icns-png.html#comments</comments>
		<pubDate>Mon, 14 Dec 2009 21:01:57 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[icônes]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[outil]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=268</guid>
		<description><![CDATA[Il m&#8217;a récemment1 fallu convertir une icône mac au format ICNS2 en une image au format  PNG. C&#8217;est ainsi que l&#8217;outil méconnu sips disponible dès Mac OS X 10.3&#160;m&#8217;est venu en aide o/


sips -s format png -s formatOptions best -Z 64 /chemin/vers/icone.icns --out /chemin/vers/icone-64.png


Petites explications&#160;:


-s format png pour spécifier le format de sortie PNG.
-s [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Il m&#8217;a récemment<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> fallu convertir une icône <strong>mac</strong> au format <strong><a href="http://en.wikipedia.org/wiki/Apple_Icon_Image" title="Apple Icon Image - Wikipedia, the free encyclopedia">ICNS</a></strong><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> en une image au format  <strong><a href="http://fr.wikipedia.org/wiki/Portable_Network_Graphics" title="Portable Network Graphics - Wikipédia">PNG</a></strong>. C&#8217;est ainsi que l&#8217;outil méconnu <a href="http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man1/sips.1.html" title="Mac OS X Manual Page For sips(1)">sips</a> disponible dès Mac OS X 10.3&#160;m&#8217;est venu en aide o/</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sips <span style="color: #660033;">-s</span> format png <span style="color: #660033;">-s</span> formatOptions best <span style="color: #660033;">-Z</span> <span style="color: #000000;">64</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>vers<span style="color: #000000; font-weight: bold;">/</span>icone.icns <span style="color: #660033;">--out</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>vers<span style="color: #000000; font-weight: bold;">/</span>icone-64.png</pre></div></div>


<p>Petites explications&#160;:</p>

<ul>
<li><code>-s format png</code> pour spécifier le format de sortie PNG.</li>
<li><code>-s formatOptions best</code> permet d&#8217;obtenir la meilleure qualité d&#8217;image bitmap.</li>
<li><code>-Z 64</code> sert à préciser les dimensions maximales du fichier de destination. Ici, l&#8217;icône .icns sera convertie en un .png de 64px de côtés.</li>
</ul>

<p>Comme vous pourrez le lire dans le man de l&#8217;outil <code>sips</code>, ce dernier supporte en sortie les formats  jpeg, tiff, png, gif, jp2, pict, bmp, qtif, psd, sgi et tga.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html' title='Rechercher le nom réel d&#8217;un utilisateur sous Leopard'>Rechercher le nom réel d&#8217;un utilisateur sous Leopard</a></li><li><a href='http://pioupioum.fr/snippets/php-installer-apc-macosx.html' title='PHP : installer APC sous Mac OS X Leopard'>PHP&#160;: installer APC sous Mac OS X Leopard</a></li><li><a href='http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html' title='Bash : convertir un string en entier'>Bash&#160;: convertir un string en entier</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html' title='WordPress : récupération avancée des images d&#8217;un article'>WordPress&#160;: récupération avancée des images d&#8217;un article</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-css-selection-unicode.html' title='TextMate : bundle CSS, commande &quot;Convertir la sélection en Unicode&quot;'>TextMate&#160;: bundle CSS, commande &quot;Convertir la sélection en Unicode&quot;</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>enfin c&#8217;est vite dit, cela fait maintenant plusieurs mois mais l&#8217;idée de noter la commande ici n&#8217;est venu que récemment =]&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>si l&#8217;icône se trouve être celle d&#8217;une application, vous la trouverez généralement dans le répertoire <code>Application.app/Contents/Resources/</code>.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/convertir-icone-icns-png.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rechercher le nom réel d&#8217;un utilisateur sous Leopard</title>
		<link>http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html</link>
		<comments>http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html#comments</comments>
		<pubDate>Thu, 06 Aug 2009 21:41:31 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=183</guid>
		<description><![CDATA[Sous Mac OS X 10.4 (ou Tiger) et versions antérieures, la lecture du nom réel d&#8217;un utilisateur pouvait se faire à l&#8217;aide de l&#8217;utilitaire niutil&#160;:


mehdi@localhost:~$ niutil -readprop / &#34;/users/$USER&#34; realname
Mehdi Kabab


Mais le passage à Mac OS X 10.5&#160;aka Leopard s&#8217;est fait sans lui. En effet, le gestionnaire NetInfo (dont niutil est un utilitaire) a disparu [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Sous Mac OS X 10.4 (ou <strong>Tiger</strong>) et versions antérieures, la lecture du nom réel d&#8217;un utilisateur pouvait se faire à l&#8217;aide de l&#8217;utilitaire <strong><a href="http://support.apple.com/kb/TA25212" title="Mac OS X Server: niutil Utility">niutil</a></strong>&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mehdi<span style="color: #000000; font-weight: bold;">@</span>localhost:~$ niutil <span style="color: #660033;">-readprop</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">&quot;/users/<span style="color: #007800;">$USER</span>&quot;</span> realname
Mehdi Kabab</pre></div></div>


<p>Mais le passage à Mac OS X 10.5&#160;<em>aka</em> <strong>Leopard</strong> s&#8217;est fait sans lui. En effet, le gestionnaire <a href="http://en.wikipedia.org/wiki/NetInfo_Manager" title="NetInfo Manager - Wikipedia, the free encyclopedia">NetInfo</a> (dont <strong>niutil</strong> est un utilitaire) a disparu du système. Il nous faut désormais recourir à l&#8217;outil <strong><a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/dscl.1.html" title="Mac OS X
 Manual Page For dscl(1)">dscl</a></strong>.<br />
Ainsi, sous Leopard, le nom réel d&#8217;un utilisateur se récupère de la sorte&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dscl . <span style="color: #660033;">-read</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$USER</span> RealName <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'!/RealName/ {sub(&quot; &quot;,&quot;&quot;); print $0}'</span></pre></div></div>


<p>Si vous souhaitez rendre cette commande compatible Mac OS X 10.4 et 10.5, utilisez la version qui suit&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dscl . <span style="color: #660033;">-read</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$USER</span> RealName <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #ff0000;">' '</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;s/^RealName:[ ]+//;s/[ ]+$//&quot;</span></pre></div></div>


<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/convertir-icone-icns-png.html' title='Convertir une icône ICNS en une image PNG'>Convertir une icône ICNS en une image PNG</a></li><li><a href='http://pioupioum.fr/snippets/php-installer-apc-macosx.html' title='PHP : installer APC sous Mac OS X Leopard'>PHP&#160;: installer APC sous Mac OS X Leopard</a></li><li><a href='http://pioupioum.fr/snippets/bash-convertir-string-to-integer.html' title='Bash : convertir un string en entier'>Bash&#160;: convertir un string en entier</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-css-selection-unicode.html' title='TextMate : bundle CSS, commande &quot;Convertir la sélection en Unicode&quot;'>TextMate&#160;: bundle CSS, commande &quot;Convertir la sélection en Unicode&quot;</a></li></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/leopard-rechercher-nom-reel-utilisateur.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
