[英]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). 我有一个shell脚本,该脚本应该创建一个文件并在其上填充两行(以使其变得简单)。
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. 确实可以,但是当我尝试将file1.py内容放入变量中时,它会缩短空间并仅保留一个空间。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.