简体   繁体   中英

linux shell leave spaces in variable

I have a shell script which is supposed to create a file and fill two lines on it (to make it simple).

echo -e "#-*- coding: utf-8 -*-
    var1 = ''" > file1.py

This does work, but when I try to put file1.py content in a variable, then it shortens spaces and keeps only one space.

content="#-*- coding: utf-8 -*-
    var1 = ''"
echo -e $content > file1.py

:( please help

before execution the command is resolved to be:

echo -e this is what is inside the content variable > file1.py

therefore you just have to quote it again:

echo -e "$content" > file1.py

which results in:

echo -e "this is what is inside the content variable" > file1.py

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