简体   繁体   中英

Write multiple lines to a file using bash for Mac

I am creating a bash file to be run in Mac PC. Basically the file creates and writes multiple lines to a file. It contains some special characters like tilde, percentage etc.

Somehow in the file created, the characters sometimes disappears or appears wrong. I am doing the standard echo line by line. Eg

echo text >> file.conf

Is there any other way to write to a file?

Try quoting your text. If you want variables expanded, use double quotes. If you do not want variables expanded, use single quotes:

echo "$HOME"   # expanded
/Users/Mark

echo '$HOME'   # not expanded
$HOME

echo *         # expanded
0.jpg 0_0.jpg 0_1.jpg 0_10.jpg 0_11.jpg 0_12.jpg 0_2.jpg 0_3.jpg 0_4.jpg

echo '*'       # not expanded
*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM