linux - 寻找匹配时意外的 EOF
问题描述
我有 jenkins 工作来执行 shell 脚本,但是在寻找匹配项时收到错误意外 EOF
servicedir="dir1"
checkdir = sh(
script: "ssh user@hostname bash -c \"' find /home -name \"${servicedir}\" | wc -l '\"",
returnStdout: true
)
返回以下错误
bash -c ''\'' find /home -name dir1'
bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file
解决方案
您应该改用三引号,这样您就不会因错误地转义双引号而被绊倒:
脚本:"""ssh user@hostname bash -c 'find /home -name "${servicedir}" | wc -l'""",
如果需要,您也可以删除该wc -l
部分并仅计算 Groovy 中的行数:
// 在远程机器上运行 find 并获取它的标准输出 检查目录 = sh( 脚本:"""ssh user@hostname bash -c 'find /home -name "${servicedir}"'""", 返回标准输出:真 ) // 计算 find 输出的行数 int num_lines = checkdir.count('\n')
推荐阅读
- java - How to update android RecyclerView items after search filter?
- c# - 时间:2019-01-10 标签:c#conversionstringencodenonasciicharacters
- google-bigquery - Big Query The job encountered an error during execution
- javascript - Attempting to do a flag check with bitwise operators for the first time
- javascript - Moving point on sphere using spherical coordinates three js
- c - C语言中的感叹号是什么意思?
- android - 如何通过单击日历视图的日期来控制回收视图?
- java - 无法使用休眠中的以下代码在 php mysql db 中创建表条目(使用 Ampps)
- android - How to overlay TextView on JavaCameraView in android
- jquery - Anchor Link Toggle Class