How can I escape an arbitrary string for use as a command line argument in Bash?

后端 未结 8 1763
时光说笑
时光说笑 2020-12-08 13:44

I have a list of strings and I want to pass those strings as arguments in a single Bash command line call. For simple alphanumeric strings it suffices to just pass them verb

8条回答
  •  天命终不由人
    2020-12-08 14:08

    You can use single quotes to escape strings for Bash. Note however this does not expand variables within quotes as double quotes do. In your example, the following should work:

    script.pl '!foo'
    

    From Perl, this depends on the function you are using to spawn the external process. For example, if you use the system function, you can pass arguments as parameters so there"s no need to escape them. Of course you"d still need to escape quotes for Perl:

    system("/usr/bin/rm", "-fr", "/tmp/CGI_test", "/var/tmp/CGI");
    

提交回复
热议问题