#!/bin/bash
echo "$(curl -s -I https://google.com|grep Server)" abc
resi:
abcer: gws
e bash -x
mostra:
++ grep Server
++ curl -s -I https://google.com
' abco 'Server: gws
abcer: gws
ma
echo abc "$(curl -s -I https://google.com|grep Server)"`
resi
abc Server: gws
In altre parole, se aggiungo del testo DOPO il comando curl, viene alterato, ma va bene se lo aggiungo prima di curl.
Cosa sta succedendo? Non riesco a capirlo.
Risposta accettata:
echo $(curl -s -I https://google.com|grep Server)|cat -A
mostra che il valore restituito da curl ha un ^M (un ritorno a capo). Quando si stampa l'output dell'arricciatura, il ritorno a capo riporta il "cursore" all'inizio della riga, dove stampa "abc", sovrascrivendo "Serv".
Nel tuo secondo tentativo, il ritorno a capo non ha effetti evidenti.