正则表达式 – 正则表达式从Bash脚本中删除注释
发布时间:2020-12-14 06:24:05 所属栏目:百科 来源:网络整理
导读:这看起来很复杂.我需要一个正则表达式来从 Bash shell脚本中删除注释. 请记住$#,${#foo},string =“this#string”,string =’that#string’,${foo#bar},${foo ## baar},以及 string="really complex args=$# ${applejack##"jack"} $(echo "$#,again")"; `ech
这看起来很复杂.我需要一个正则表达式来从
Bash shell脚本中删除注释.
请记住$#,${#foo},string =“this#string”,string =’that#string’,${foo#bar},${foo ## baar},以及 string="really complex args=$# ${applejack##"jack"} $(echo "$#,again")"; `echo this is a ${#nasty[*]} example` 都是有效的shell表达式,不应该被剥离. 编辑: # This is a comment in bash # But so is this echo "foo bar" # This is also a comment 编辑: cat<<EOF>>out.txt This is just a heredoc # This line looks like a comment,but it isn't EOF
你不能用正则表达式做到这一点.
echo ${baz/${foo/${foo/#bar/foo}/bar}/qux} 您需要匹配嵌套大括号.正则表达式不能这样做,除非你愿意考虑PCRE的“正则表达式”,在这种情况下,在Perl中编写解析器会更简单. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |