简体   繁体   English

PyBugz Bash变量\\ n换行符被忽略

[英]PyBugz Bash Variables \n newline is ignored

i have a bash script, that extracts the bugs from a csv file and imports it into bugzilla using PyBugz. 我有一个bash脚本,它从csv文件中提取bug并使用PyBugz将其导入bugzilla。

The following sequences are used: 使用以下序列:

description=$(echo "$line" |cut -f5 -d ';')
bugz -d 3 -b http://bugzilla/bugzilla/xmlrpc.cgi -u "$user" -p "$pass" post --product "$prod" --component "$compo" --title "$title" --description "$description" --op-sys "$ops" --platform "$platf" --priority ""$prio"" --severity "$sever" --alias "$alias" --assigned-to "$assign" --cc "$ccl" --version "$ver" --url "$url" --append-command "$appen" --default-confirm "y"

but the description line containing "blablabla \\n blablabla" including the newline is beeing recognized as 但包含新行的“blablabla \\ n blablabla”的描述行被认为是

"Description : blablabla n blablabla" “描述:blablabla n blablabla”

If I export a bug and dump the output into a textfile, pybugz puts a 0x0a as newline character. 如果我导出错误并将输出转储到文本文件中,pybugz会将0x0a作为换行符。 how can I make pybugz recognize my \\n character as 0x0a?? 如何让pybugz将我的\\ n字符识别为0x0a?

If description contains the characters \\ n , and you want to convert that into an actual newline, then you'll have to do some work: 如果description包含字符\\ n ,并且您想将其转换为实际的换行符,那么您将不得不做一些工作:

bugz ... --description "$(echo -e "$description")" ...

That will expose other escape sequences as well, see https://www.gnu.org/software/bash/manual/bashref.html#index-echo 这也会暴露其他转义序列,请参阅https://www.gnu.org/software/bash/manual/bashref.html#index-echo

I got it. 我知道了。

The way to catch the data was done in the following way: 捕获数据的方法是通过以下方式完成的:

while read line ; do
description=$(echo "$line" |cut -f5 -d ';')
done <csvfile

however, the read already changed the \\n string to n so whatever I did after that was obviously a failure. 但是,读取已经将\\ n字符串更改为n,所以无论我在那之后做了什么,显然都是失败的。

I did it in a very unnice way now but it works like a charm 我现在以一种非常不明智的方式做到了,但它就像一个魅力

lines=$(cat csvexport |wc -l)
for (( lineno=1 ; $lineno<=$lines ; lineno++ )); do
description=$(cat csvexport |sed -n "$lineno"p |cut -f5 -d ';')
done

and everything is fine ;-) Thanks anyway for the help. 一切都很好;-)无论如何,谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM