Escape single quotes in shell script

前端 未结 2 662
遥遥无期
遥遥无期 2021-01-28 04:22

I need to escape single quotes in a variable.

ssh_command \'file=$(hostname)_server-setup_$(date +%Y-%m-%d).tar.gz && cd /var && tar -zcvf $file          


        
2条回答
  •  孤独总比滥情好
    2021-01-28 04:27

    For this not too big command I would not overcomplicate it and stick to the original double quotes, and escape just the $ which should not be expanded locally.

    ssh_command "file=\$(hostname)_server-setup_$(date +%Y-%m-%d).tar.gz && cd /var && tar -zcvf \$file ini | wc -l | xargs printf 'Num files: %d, File: \$file'" 
    

提交回复
热议问题