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.
我想将一个字符串写入文件,但它不起作用。我确信我错过了一些微不足道的事情。这些文件还不存在。为什么下面的脚本没有在文件中写入任何内容?甚至没有创建文件。
#!/bin/bash j="nch" temp_dir="~/temp_temp" echo "$temp_dir/$j" echo "c'mon" >> "$temp_dir/$j" echo "c'mon" >> "~/temp_temp/pch"
~不在带引号的字符串中展开。
~
temp_dir=~/temp_temp echo "c'mon" >> ~/temp_temp/pch
或者
temp_dir=~/"temp_temp" echo "c'mon" >> ~/"temp_temp/pch"
等等