Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

printf prints commas to file

I’m having an environment variable that get’s printed to a file which is then read by my program. When the variable gets written to the file it looks like this:

-----BEGIN
,RSA
,PRIVATE
,KEY-----
,MIIEowIBAAKCAQEAtxPgpPqD1cZdoTeOMvOnqp0NkkCqcMsn8V4j9KrFWpPxiweu
,H1r69S2ssmuqtleLVKk2kwgTn6x+AvcqgTBLsjnfpPmD2mBKvTqCvaBT2VXdxGiA
,dlp  etc....

When it should look like this:

-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtxPgpPqD1cZdoTeOMvOnqp0NkkCqcMsn8V4j9KrFWpPxiweu
H1r69S2ssmuqtleLVKk2kwgTn6x+AvcqgTBLsjnfpPmD2mBKvTqCvaBT2VXdxGiA
dlpJMJAvCwBsDnDRilSRoNja4DpF26bHSQePwZF1/4OqnF6GtvGcPPPENiJkjxr/ etc...

My script command looks like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

- printf '%s\n', $PRIVATE_KEY > $CI_PROJECT_DIR/private.pem

What am I doing wrong?

>Solution :

printf '%s\n' "$PRIVATE_KEY" > "$CI_PROJECT_DIR"/private.pem

Quote "$PRIVATE_KEY" to prevent it from being split into separate words. As a rule of thumb, always quote variable expansions to prevent accidental mangling of their values. It’s a good habit to get into.

Also, remove the trailing comma from '%s\n',. Shell script arguments are not comma-separated.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading