CP退出了64错误状态 [英] cp exits with a 64 error status
问题描述
我使用的是preflight bash脚本中的 packagemaker
I am using a preflight bash script in packagemaker :
运行CP -pf/文件夹/到/我/ DB/库/ Application Support /应用/数据库
run函数(即我StackOverflow上发现的方式):
The run function (that I found on StackOverflow by the way) :
的run(){$ *; code = $ ?; [$$ C $ç-ne 0]放大器;&安培; echo命令[$ *],错误code $ $ C $ç\\ n错误失败:$ @ \\ n; }
命令 CP
返回64 code。这是什么64的状态吗?
我该如何解决?
The command cp
returns a 64 code. What is this 64 status please?
How can I resolve that?
推荐答案
的问题是,你没有一个文件夹支持/应用/数据库
的命令复制文件 /文件夹/到/我/ DB
和 /库/应用程序
到
The problem is that you don't have a folder Support/app/db
for the command to copy files /folder/to/my/db
and /Library/Application
to.
替换错误的(几乎总是错的) $ *
用正确的$ @
:
Replace the misguided (almost always wrong) $*
with the correct "$@"
:
run()
{
"$@"
code=$?
[ $code -ne 0 ] && echo "command [$*] failed with error code $code\nERROR: $@\n"
}
平原 $ *
在空间打破字; $ @
preserves在争论的空间。大多数情况下, $ *
是不正确的符号(虽然这将是在回声
,您使用<$罚款C $ C> $ @ )。为什么该命令的参数错误消息被列出了两次,是我也不清楚。
Plain $*
breaks words at spaces; "$@"
preserves spaces in arguments. Most often, $*
is not the right notation (though it would be fine in the echo
where you used $@
). It isn't clear to me why the command's arguments are being listed twice in the error message.
错误报告将通过增加改善&GT;和2
到最后输出到标准错误,这是在错误信息属于重定向。 (而我在这我想删除的重复。)请注意,使用 $ *
的参数内部回声
是完全适当的。
The error reporting would be improved by adding >&2
to the end to redirect the output to standard error, which is where error messages belong. (I'd remove the repetition while I'm at it.) Note that using $*
inside the argument to echo
is entirely appropriate.
[ $code -ne 0 ] && echo "command [$*] failed with error code $code" >&2
其实,的run()
功能可以更加简化;变量 code
真的不需要
In fact, the run()
function can be simplified still more; the variable code
really isn't needed:
run()
{
"$@" || echo "command [$*] failed with error code $?" >&2
}
如果您希望脚本退出过,那么你可以使用:
If you want the script to exit too, then you can use:
run()
{
"$@" || { echo "command [$*] failed with error code $?" >&2; exit 1; }
}
的 {...; }
符号把命令中作为一个单元进行I / O重定向,而无需启动一个子shell。
The { ...; }
notation treats the commands within as a unit for I/O redirection without starting a sub-shell.
又见<一个href=\"http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script/256225#256225\">How迭代变量在Bash脚本。
这篇关于CP退出了64错误状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!