Escaping double quotes with tcsh alias

后端 未结 5 690
轻奢々
轻奢々 2020-12-11 21:55

I\'m trying to run the following commands:

replace -x \"must \" A2input.txt
replace -x \" a\" -f -s ## A2input.txt
replace -x to -s ## -a A2input.txt
replace         


        
5条回答
  •  暖寄归人
    2020-12-11 22:23

    The following all work in tcsh to accomplish various results:

    alias t echo hello world                # you may not actually need any quotes
    alias u 'echo "hello world"'            # nested quotes of different types
    alias v echo\ \"hello\ world\"          # escape everything
    alias w echo '\;'hello'";"' world       # quote/escape problem areas only
    alias x 'echo \"hello world\"'          # single quote and escape for literal "
    alias y "echo "\""hello world"\"        # unquote, escaped quote, quote ("\"")
    alias z 'echo '\''hello world'\'        # same goes for single quotes ('\'')
    

    To see how these are interpreted by the shell, run alias with no arguments:

    % alias
    t       (echo hello world)
    u       echo "hello world"
    v       echo "hello world"
    w       (echo \;hello";" world)
    x       echo \"hello world\"
    y       echo "hello world"
    z       echo 'hello world'
    

    Anything in parentheses is run in a subshell. This would be bad if you're trying to set environment variables, but mostly irrelevant otherwise.

    Finally, here's what the examples actually do:

    % t; u; v; w; x; y; z
    hello world
    hello world
    hello world
    ;hello; world
    "hello world"
    hello world
    hello world
    

提交回复
热议问题