If I use curl
in a Terminal window on Ubuntu 16.04 to ask WordPress for some secret keys, I get a nice pretty output with each item on a new line:
$ curl -s https://api.wordpress.org/secret-key/1.1/salt/
define('AUTH_KEY', '6w$JwCO^;NW3vnWgQ|Hj=8T-K_ 7W/0|9WYKk`uVI|m/l#(y8^KYdvw,jo`l1qpz');
define('SECURE_AUTH_KEY', 'ccEN8qnoDVD|T#j7uCI%P+mt[tslr.> ZD=lr|y^XQ$/D)xGjvKqQ7_*v#,jVr+T');
define('LOGGED_IN_KEY', 'Qt)KLgcof#0TD0Sr3wC7jS=0}=8O]GVV(v+:^QfR|YtyP&N])8|@$tt!mFk]mQ:N');
define('NONCE_KEY', '^9#+{Qh7H3PI1IUT5Ps~4v.-0FSA&*VKHHB|,:.uKIs(kj*vC4rD!,0&|`1HE^:E');
define('AUTH_SALT', '{hL|~vC@{SSpK(t/{bu+LPej7Ld.J-X_hqB-|i8^0pMI3~$]Ta>*zr.JV-b{R?q9');
define('SECURE_AUTH_SALT', 'mn4oN^fSiEi->=v3_D;z608bebv#Nr crSh:Jk`FbmF;-<`X5X}<YD1fnx|:-$g ');
define('LOGGED_IN_SALT', 'V|`(qBQSQxw(ti-5vy!!8wviPI,cz!tfz1r?qvQzg,rW,w&K`-hRh.~w]yX^ui0h');
define('NONCE_SALT', '?/N1{=`2Lp+c|6wK]m:@V-^FQY[.G7wb.pd6KQ@Z$&gF1s`ggKH;G|/3,d:qTlDZ');
If I first save the result to a variable, and then look at the contents of the variable, everything has become a single-line porridge:
keys=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/); echo; echo $keys
define('AUTH_KEY', 'Q$<~=k -4Dw6J05xHrzW`<4hg>.q?hbk|BV{y5b8Z$ddd-ZH]r2|0`?s<Q4#6.!k'); define('SECURE_AUTH_KEY', 'yV:ZN5sL&rLAN,Ss`~4>]WgtTIb[UG9s+BDNG=.zpN)r5~Ps>@Qxll0,@zz9F%h`'); define('LOGGED_IN_KEY', '+RW:%+<XAAiqD-~w!R(2+]vPD+%x/(|ur-$D+C8/U-F:ExkZ1O{05H5(Uk9#~(o]'); define('NONCE_KEY', ';aQuNt)c3#C~0F?vnh?12gxMY+z()0 t1y2_v2,?Sm`!uZppn+3pRwlXX}Rt8aL9'); define('AUTH_SALT', '1inr)T||(uk{Ivk?]~UR/=`}GlM|[Y`0%=_1)=p<EV&(b%wy,+EMG-xvY-G!tIF<'); define('SECURE_AUTH_SALT', '9+K!7eEQ5N&C#?`.D+0nTF-S|P!&n+O -|=n0;an|Pl78[|uQ9kbz,i+N_y/@p]r'); define('LOGGED_IN_SALT', 'NtDSfos]0/ ~x*4%22IVM:<XbNI1MKJw=>HHGg{|g91<zjXWR&Zhj*z&-j:7U2nS'); define('NONCE_SALT', '%Yo>D7nLM~IS|HrnSL<0&/4#-zW+M+b^d -Q pZ*9$Cu^@h)qFD9. |R&[?[p>cZ');
My question is: why are the line-breaks getting mistreated when the string is assigned to a variable?
Note: to put this question in context, I am writing a script to install WordPress automatically. I already have a solution that neatly adds unique salt values to the wp-config.php
file, the way I want it, so my immediate issue is solved:
#!/usr/bin/env bash
source=wp-config-sample.php
target=wp-config.php
grep -A 1 -B 60 'since 2.6.0' $source > $target
curl -K -s https://api.wordpress.org/secret-key/1.1/salt/ >> $target
grep -A 60 -B 4 'Table prefix' $source >> $target
It's just that the treatment of the line-breaks when the string is assigned to a variable bothers me, and I want to understand what is happening, and why.
echo
converts unquoted line breaks to spaces:
$ X='a
> b'
$ echo $X
a b
$ echo "$X"
a
b