<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[PublMe - Space: Posted Reaction by PublMe bot in PublMe]]></title>
	<link>https://publme.space/reactions/v/39789</link>
	<atom:link href="https://publme.space/reactions/v/39789" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://publme.space/reactions/v/39789</guid>
	<pubDate>Wed, 22 May 2024 20:30:12 +0200</pubDate>
	<link>https://publme.space/reactions/v/39789</link>
	<title><![CDATA[Posted Reaction by PublMe bot in PublMe]]></title>
	<description><![CDATA[
<p>Amber Compiles to Bash</p>
<div><img width="800" height="250" src="https://hackaday.com/wp-content/uploads/2024/05/amber.png?w=800" alt="" srcset="https://hackaday.com/wp-content/uploads/2024/05/amber.png 800w, https://hackaday.com/wp-content/uploads/2024/05/amber.png?resize=250, 78 250w, https://hackaday.com/wp-content/uploads/2024/05/amber.png?resize=400, 125 400w" data-attachment-id="681048" data-permalink="https://hackaday.com/2024/05/22/amber-compiles-to-bash/amber/" data-orig-file="https://hackaday.com/wp-content/uploads/2024/05/amber.png" data-orig-size="800,250" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="amber" data-image-description="" data-image-caption="" data-medium-file="https://hackaday.com/wp-content/uploads/2024/05/amber.png?w=400" data-large-file="https://hackaday.com/wp-content/uploads/2024/05/amber.png?w=800"></div><p>It certainly isn’t a new idea to compile a language into an intermediate language. The original C++ compiler outputs C code, for example. Enhanced versions of Fortran were often just conversions of new syntax to old syntax. Of course, it makes sense to output to some language that can run on lots of different platforms. So, using that logic, <a rel="nofollow" href="https://amber-lang.com/" target="_blank">Amber</a> makes perfect sense. It targets — no kidding — bash. You write with nice modern syntax and compile-time checks. The output is a bash script. Admittedly, sometimes a hard-to-read bash script, but still.</p><p>If you want to see the source code, it is available on <a rel="nofollow" href="https://github.com/Ph0enixKM/Amber" target="_blank">GitHub</a>. Since Windows doesn’t really support bash — if you don’t count things like Cygwin and WSL — Amber only officially supports Linux and MacOS. In addition to compiling files, Amber can also execute scripts directly which can be useful for a quick one-liner. If you use Visual Studio Code, you can find a syntax highlighter extension for Amber.</p><p></p><p>To get a flavor of how it works, here’s a simple Amber file to rename some files:</p><pre>
let files = ["config.json", "file.txt", "audio.mp3"]

loop index, file in files {
   $mv {file} {index}{file}$ failed {
      echo "Failed to rename {file}"
   }
}
</pre><p>Here’s the output shell script:</p><pre>
__AMBER_ARRAY_0=("config.json" "file.txt" "audio.mp3");
__0_files=("${__AMBER_ARRAY_0[@]}");
index=0;
for file in "${__0_files[@]}"
do
   mv ${file} ${index}${file}
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
   echo "Failed to rename ${file}"
fi
   let index=${index}+1
done
</pre><p>Looks much easier. Still, bash isn’t that hard. If you must have bash scripts for some reason, this might be worth a look. As a general-purpose programming language, you should probably stick with something more traditional.</p><p>Catching errors early is a good thing, but there <a rel="nofollow" href="https://hackaday.com/2017/03/29/lint-for-shell-scripters/">are other ways to do that</a>. While you could probably use a <a rel="nofollow" href="https://hackaday.com/2019/12/11/linux-fu-debugging-bash-scripts/">debugger</a> on the output bash code, it looks a bit hard to follow, so an Amber debugger would be welcome.</p>]]></description>
	<dc:creator>PublMe bot</dc:creator>
</item>

</channel>
</rss>