question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Carriage return `\r` being appended to the output

See original GitHub issue

This is autogenerated. Please review and update as needed.

Describe the bug

Getting the following error when trying to query the IP address of a NIC for which I had already pulled the ID and sent as a parameter in the show command. Operation failed with status: ‘Bad Request’. Details: 400 Client Error: Bad Request for url: https://management.azure.com/subscriptions/......./resourceGroups/......./providers/Microsoft.Network/networkInterfaces/…?api-version=2020-04-01

Command Name az resource show

Errors:

az: error: unrecognized arguments: \ \ \

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here…
  • az resource show --name {} {} --resource-group {} {} --resource-type {} {} --query {} -o {}

Expected Behavior

Environment Summary

Windows-10-10.0.17763-SP0
Python 3.6.6
Installer: 

azure-cli 2.6.0

Extensions:
interactive 0.4.4

Additional Context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
arekpalinskicommented, Jun 18, 2020

I think I’ve run into the same issue. I followed the following example:

https://docs.microsoft.com/en-us/azure/event-grid/custom-event-to-queue-storage#subscribe-to-a-custom-topic

so I had a script like:

storageid=$(az storage account show --name $storageAccountName --resource-group $storageResourceGroup --query id --output tsv | tr -d '\r')
queueid="$storageid/queueservices/default/queues/$queueName" 

az eventgrid event-subscription create --source-resource-id $storageid --name $eventSubscriptionName --endpoint-type storagequeue --endpoint $queueid --included-event-types Microsoft.Storage.BlobCreated

what resulted in Operation failed with status: 'Bad Request'. Details: 400 Client Error: Bad Request for url: because of %0D character in the middle of URL. I have workaround this by adding | tr -d '\r' here:

storageid=$(az storage account show --name $storageAccountName --resource-group $storageResourceGroup --query id --output tsv | tr -d '\r')
2reactions
jiaslicommented, Jul 29, 2021

There are 2 ways to trigger this issue on WSL.

Calling az installed on Windows

If you are calling az installed on Windows system instead of the az installed on WSL Linux, you will hit this issue.

To identify which az you are calling, run

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

# az installed on WSL Linux
$ which az
/usr/bin/az

Call az installed on Windows, save the result and let python3 help us display its raw value:

$ result=$(az account show --query id --output tsv)
$ python3 -c "import sys; print(sys.argv)" "$result"
['-c', '0b1f6471-1bf0-4dda-aec3-cb9272f09590\r']

Solution

Always stay in WSL Linux. Make sure az is installed following Install the Azure CLI on Linux and /mnt/c/Program Files (x86)/Microsoft SDKs/Azure/CLI2/wbin/az is not called.

Now it works correctly:

$ result=$(az account show --query id --output tsv)
$ python3 -c "import sys; print(sys.argv)" "$result"
['-c', '6b085460-5f21-477e-ba44-1035046e9101']

Executing .sh script with CRLF

As @zhoxing-ms stated in https://github.com/Azure/azure-cli/issues/13573#issuecomment-650686531, say we have test.sh with CRLF as End of Line Sequence:

result="somevalue"
python3 -c "import sys; print(sys.argv)" "$result"

When executing the script in WSL:

$ . test.sh
['-c', 'somevalue\r\r']

Solution

To fix it, you may open the script with VS Code:

code test.sh

Select End of Line Sequence and change it to LF:

image

Now it works correctly:

$ . test.sh
['-c', 'somevalue']
Read more comments on GitHub >

github_iconTop Results From Across the Web

Carriage return \r on bash script - Stack Overflow
I have this bash script on my CentOS 5.3. ... I've noticed that "\r" output is attached on the value. I would appreciate...
Read more >
In shell scripting, how do I add carriage return to the output ...
In BASH, for example, you can output a carriage return character with: echo -e -n “\r” ... echo -n "${OUT}" >> file #...
Read more >
Carriage return with echo command - Unix Stack Exchange
The \r is just that, a "carriage return" - nothing else. This means what is after the \r will overwrite the beginning of...
Read more >
Remove "\r" from echoing out in bash script - Super User
I came across this problem when using cygwin bash against output from the standard (non-cygwin) version of python; I'm confused as to why...
Read more >
How to remove carriage return in Linux or Unix - nixCraft
Removing carriage return in Linux or Unix · Open the terminal app and then type any one of the following command. · Use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found