bash : replace variable value inside ' '

后端 未结 3 1002
天涯浪人
天涯浪人 2021-01-15 04:23

Sorry if the question is very straight forward but am a newbie to shell scripting. I am trying to write something like this :

for i in {1..20}
do
   curl \"         


        
3条回答
  •  迷失自我
    2021-01-15 04:49

    As said above, parameters are not expanded inside single quotes, you have to use double quotes. The only point is that since it occurs in a already double-quoted string, you have to escape them with a backslash (\), like this:

    $ foo=bar
    $ eval "echo \"something \\\"$foo\\\"\""
    something "bar"
    

    Note that there are three \ before the innermost ", as this will be expanded twice (once when evaluating the argument of eval and once when evaluating the argument of echo)

提交回复
热议问题