How do I run the printf command on a Windows 10 PC that uses Linux Containers?

4/8/2020

I have come across this Helm chart for SQL Server 2017: https://github.com/helm/charts/tree/master/stable/mssql-linux

It looks very useful. So I have followed the instructions:

  1. helm install --name mymssql stable/mssql-linux --set acceptEula.value=Y --set edition.value=Developer

    This works as expected i.e. the kubectl commands below it return the expected results. It then says:

  2. printf $(kubectl get secret --namespace default mymssql-mssql-linux-secret -o jsonpath="{.data.sapassword}" | base64 --decode);echo

I have run this in a command prompt and in Powershell and it just says printf is not recognised (as I expected). How do I run the printf command on a Windows 10 PC that uses Linux Containers?

I have spent time Googling it, which tells me that printf is a C++ function. How do I follow step 2?

-- w0051977
docker
kubernetes

1 Answer

4/8/2020

The required data is printed by the kubectl command within the $().

The base 64 decoding can be done within kubectl itself via Go templates rather than piping the kubectl output into base64 (which probably doesn't exist on windows without mssys installed)

kubectl get secret mymssql-mssql-linux-secret -o go-template='{{.data.sapassword | base64decode}}'

The printf/echo additions in the example command seem redundant, or at least a bad way to get a newline after the output. If you find you need a new line to be added on the end of the output on Windows, use the following template

'{{.data.sapassword | base64decode}}{{ "\n" }}'
-- Matt
Source: StackOverflow