我正在尝试在bash heredoc中插入变量:
var=$1
sudo tee "/path/to/outfile" > /dev/null << "EOF"
Some text that contains my $var
EOF
这并不像我期望的那样工作($var
是逐字处理的,而不是扩展的)。
我需要使用sudo tee
,因为创建文件需要sudo。做一些类似的事情:
sudo cat > /path/to/outfile <<EOT
my text...
EOT
不起作用,因为>outfile
在当前shell中打开文件,而当前shell没有使用sudo。
https://stackoverflow.com/questions/4937792
复制相似问题