Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Az cli add additional new line into string output #21457

Closed
chinadragon0515 opened this issue Feb 28, 2022 · 6 comments
Closed

Az cli add additional new line into string output #21457

chinadragon0515 opened this issue Feb 28, 2022 · 6 comments
Assignees
Labels
Auto-Assign Auto assign by bot Core CLI core infrastructure feature-request Knack

Comments

@chinadragon0515
Copy link

For command like
az k8s-extension show
--cluster-type connectedClusters
--cluster-name $clusterName
--resource-group $groupName
--name $extensionName
--query id
--output tsv > id.txt

If we open id.txt, we can see it has string with additional new line, and this is some for other commands like az monitor related cli.

This will cause some issue when to use these output.

Expected behavior, no new line for single string output.

@ghost ghost added Auto-Assign Auto assign by bot Monitor az monitor labels Feb 28, 2022
@ghost ghost assigned kairu-ms Feb 28, 2022
@ghost ghost added this to the Backlog milestone Feb 28, 2022
@yonzhan yonzhan added AKS az aks/acs/openshift CXP Attention This issue is handled by CXP team. labels Feb 28, 2022
@ghost
Copy link

ghost commented Feb 28, 2022

Thank you for your feedback. This has been routed to the support team for assistance.

@kairu-ms kairu-ms added Core CLI core infrastructure and removed Monitor az monitor AKS az aks/acs/openshift CXP Attention This issue is handled by CXP team. labels Feb 28, 2022
@kairu-ms
Copy link
Contributor

It seems -o tsv will add a newline at the end of output.

@kairu-ms kairu-ms assigned jiasli and unassigned kairu-ms Feb 28, 2022
@kairu-ms kairu-ms added the Knack label Feb 28, 2022
@kairu-ms
Copy link
Contributor

@chinadragon0515
Copy link
Author

this is a breaking changes and cause all the doc which has base64 encoding will not work for customer, can we make this as high priority?

@jiasli
Copy link
Member

jiasli commented Mar 16, 2022

--output tsv outputting a value with \n has been the design of Azure CLI since its birth.

tsv stands for tab-separated values, so each item is considered a row. There is no "single string", but only list with single row. Actually during Bash variable assignment, the trailing new line is removed automatically:

$ name=$(az group show -n clitest.rg6i4hl6iakg --query name --output tsv)
$ echo -n $name; echo something more
clitest.rg6i4hl6iakgsomething more

https://www.gnu.org/software/bash/manual/bash.html#Command-Substitution

Bash performs the expansion by executing command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.

You are seeing this issue because your are running Azure CLI installed on Windows via WSL:

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

This hits issue:

To solve it, please follow https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt to install Azure CLI in WSL Ubuntu, so that Linux az is called:

$ which az
/usr/bin/az

@jiasli
Copy link
Member

jiasli commented Mar 16, 2022

BTW, you may check what's actually in the variable using a very simply Python script:

$ python3 -c "import sys; print(sys.argv)" $name
['-c', 'clitest.rg6i4hl6iakg\r']

Note the \r in $name.

@jiasli jiasli closed this as completed Mar 16, 2022
@jiasli jiasli modified the milestones: Backlog, Mar 2022 (2022-04-06) Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot Core CLI core infrastructure feature-request Knack
Projects
None yet
Development

No branches or pull requests

4 participants