When we finished last time, I’d just run a simple bash script with some surprising output.

$ ./provision.sh
--XISTS=--false
resource group exists

Seeing the -- show up at the start of the line is odd - where do those characters come from? I expected to see -- at the end of the line, not the start.

What’s happening?

The -- showing up at the start of the line is actually written last, overwriting the initial $E.

It turns out that the az command is returning six characters, not five!

Instead of false, it is returning false\r - the expected string, with an extra trailing carriage return character.

But why?

Searching online, I found a clue that led me to the root cause of my pain.

$ which az
/mnt/c/Program Files (x86)/Microsoft SDKs/Azure/CLI2/wbin/az

I was (quite accidentally!) running the Windows version of az, which naturally was writing CRLF (\r\n) at the end of each line of output, instead of the simple LF (\n) expected by Linux.

On the one hand, it’s kind of nice to have things so smoothly integrated that the Windows version of the Azure CLI works for most uses even from Linux.

On the other hand, I did spend a couple of hours doubting my ability to write a simple bash script because even the simple things didn’t appear to work.

On the gripping hand, installing the Linux version of the Azure CLI was as simple as sudo apt install azure-cli.

$ which az
/usr/bin/az

And now everything works.

Comments

blog comments powered by Disqus
Next Post
Method Archetypes  11 Sep 2022
Prior Post
A bash puzzle  25 Jun 2022
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
When are you done?  18 Apr 2022
Archives
July 2022
2022