我想在bash脚本中添加一个替换
的sed命令#archive_command = ''
到
archive_command = 'rsync -a %p barman@$BACKUP_SERVER_IP:$INCOMING_WALS_DIRECTORY/%f'
我不是专家,我总是遇到错误。我猜是单引号和双引号
sudo sed -i "s!#archive_command = ''!archive_command = 'rsync -a %p barman@$BACKUP_SERVER_IP:$INCOMING_WALS_DIRECTORY/%f'!" "/my/archive"
感谢任何帮助。
答案 0 :(得分:1)
尝试:
sudo sed -i "/^#archive_command = /s|.*|archive_command = 'rsync -a %p barman@\$BACKUP_SERVER_IP:\$INCOMING_WALS_DIRECTORY/%f'|" file
如果您希望扩展这些变量,请不要引用:
sudo sed -i "/^#archive_command = /s|.*|archive_command = 'rsync -a %p barman@$BACKUP_SERVER_IP:$INCOMING_WALS_DIRECTORY/%f'|" file
答案 1 :(得分:0)
...或者使其更具可读性:):
sed "s/\(#\)\(.[^']*\)\('\)\('\)/\2\3rsync -a %p barman@\$BACKUP_SERVER_IP:\$INCOMING_WALS_DIRECTORY\/%f\4/" file