"参数太多" shell脚本

时间:2017-01-05 01:05:25

标签: bash shell syntax

这是我的剧本:

if [ awk '$0 ~ /Failed/ { print }' $(pwd)/unity.log ]; then
    echo "Build Failed"
    exit 1
else
    echo "Build Success"
    exit 0
fi

要点是我正在检查文件" Build Failed"如果失败,则退出1并退出。

如果我理解的是正确的话,如果文件中没有文字,awk将返回空白字符串,如果找到,则会返回一些文字。但它会发出语法错误:./Scripts/build.sh: line 41: [: too many arguments

3 个答案:

答案 0 :(得分:4)

删除UIApplicationShortcutWidget,使用[]

grep

答案 1 :(得分:2)

您可以利用默认退出值为0.此外,没有理由library(ggplot2) library(Hmisc) library(grid) p = ggplot(mtcars,aes(x=gear,y=cyl)) + stat_summary(aes(color=as.factor(rep(1:2,16))), fun.data=mean_cl_boot, position=position_dodge(0.4)) + coord_flip() g = ggplotGrob(p) # Get names of segment grobs grid.ls(grid.force(g))$name # "GRID.segments" # Check the structure of the segment grobs str(getGrob(grid.force(g), gPath("GRID.segments"), grep = TRUE, global = TRUE)) # Edit the segment grobs using the editGrob() function # 1) Rotate the segments g <- editGrob(grid.force(g), gPath("GRID.segments"), grep = TRUE, global = TRUE, vp = viewport(angle = 90)) # 2) set end points of segments # g <- editGrob(grid.force(g), gPath("GRID.segments"), grep = TRUE, global = TRUE, # x0 = unit(0.1, "npc"), y0 = unit(0.5, "npc"), x1 = unit(0.9, "npc"), y1 = unit(0.5, "npc")) # Draw it grid.newpage() grid.draw(g) ;只需$(pwd)/filename

filename

将失败时的错误消息发送到grep -qw Failed unity.log || { echo "Build Failed"; exit 1; } echo "Build Success" stderr)也会更加惯用。

答案 2 :(得分:-2)

试试这个:

if [ ! "$(grep 'Build Failed' unity.log)" ]; then
    exit 1
fi