我有这个代码:
echo 'deb http://nginx.org/packages/debian/ wheezy nginx' >> /tmp/nginx.list
echo 'deb-src http://nginx.org/packages/debian/ wheezy nginx' >> /tmp/nginx.list
cp /tmp/nginx.list /etc/apt/sources.list.d/
rm /tmp/nginx.list
这似乎很啰嗦。是否有更直接的方法将此信息放入文件中而无需使用 tmp 文件?
最佳答案
一种方法是使用 heredoc :
cat > /etc/apt/sources.list.d/nginx.list << EOF
deb http://nginx.org/packages/debian/ wheezy nginx
deb-src http://nginx.org/packages/debian/ wheezy nginx
EOF
关于linux - Bash 将值加载到文件中的更直接方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22505739/