Monday 15 September 2014

regex - sed uses parameter from a string contained space -


I am writing my function to convert an effective option into a file in my settings. 1.txt is like:

  PasswordAction Yes PermitTutu LOGIN Yes   

My function will process the file, like output:

 The code created by the string created by the function is sed_chain (), like the following: The problem is the following:  # Password Authentication Yes Password not authentication # Permiter login Login Yes Permit Root not logged in   

That's the place between $ $ {pattern} and $ {option}, then I get an error: sed: -e exp Corporation # 1, four 46: unbalanced `s' command

If among them there is no place, then the function works, but I do what I want it.

  #! / Bin / bash A = "no password authentication" B = "permit root not logged in" F = "/ tmp / 1.txt" sed_chain () {args = ("$ @") file = $ {@: (- 1)} Pattern_par = "$ i in $ (seq 0 $ (($ # - 2))) Pattern = $ (echo $ {argets [$ i]} | cut-d" "-f1) option = $ (echo $ {Argues [$ i]} | cut-d "" -f2) counterchange $ pattern echo $ option pattern_params = "- es / ^ [^ #] * $ {pattern} * $ / # & Amp; \ N $ {pattern} $ {option} / g $ pattern_params "#file # pattern_param = '-es / ^ [^ #] *' $ {pattern} '. * $ / # And' '\ n $ { Pattern} $ {option} "'/ g' $ {pattern_param} # passed echo" *** $ Pattern_params *** "sed $ pattern_params $ file} sed_chain" $ A "" $ B "" $ F "  

Try wrapping single-quotes around the expression.

  pattern_params = "- es / ^ [^ #] * $ {pattern}. * $ / # & Amp; \ n $ {pattern} $ {option} / g '$ pattern_params"    

No comments:

Post a Comment