문제

I only see spaces, no new lines.

script.sh:

STRING=$(echo "alpha,beta,gamma,delta" | tr "," "\n")
echo $STRING > string.txt

Result:

$ cat string.txt
alpha beta gamma delta

Desired result

$ cat string.txt
alpha
beta
gamma
delta
도움이 되었습니까?

해결책

Try quoting the $STRING variable:

echo "$STRING" > string.txt

e.g:

$ STRING=$(echo "alpha,beta,gamma,delta" | tr "," "\n")
$ echo $STRING
alpha beta gamma delta
$ echo "$STRING"
alpha
beta
gamma
delta
$ 

다른 팁

BASH / shell doesn't usually work right without quoting, make sure to use it here to get new lines in your file:

echo "$STRING" > string.txt

See official manual on world splitting (Thanks to Glenn)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top