Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 shell 脚本,它应该创建一个文件并在上面填充两行(为了简单起见)。
echo -e "#-*- coding: utf-8 -*- var1 = ''" > file1.py
这确实有效,但是当我尝试将 file1.py 内容放入变量时,它会缩短空格并仅保留一个空格。
content="#-*- coding: utf-8 -*- var1 = ''" echo -e $content > file1.py
:( 请帮忙
在执行之前,命令被解析为:
echo -e this is what is inside the content variable > file1.py
因此你只需要再次引用它:
echo -e "$content" > file1.py
这导致:
echo -e "this is what is inside the content variable" > file1.py