我在git中运行预提交挂钩时遇到错误,我无法弄明白。这是脚本,错误如下。
#!/bin/bash
# Pre-commit hook passing files through jslint and uglify
#ROOT_DIR=$(git rev-parse --show-toplevel)
JSLINT="/home/john/Projects/node/uglify/node_modules/.bin/jslint --indent 4 --white true -nomen"
UGLIFYJS="/home/john/Projects/node/uglify/node_modules/.bin/uglifyjs"
JS_TEMP_EDITOR="/home/john/Projects/node/test/generated/tmp/_combined_editor.js"
JS_COMBINED_EDITOR="/home/john/Projects/node/test/public/javascripts/editor.min.js"
# Where the editor files are located
BASE="/home/john/Projects/node/test/public/javascripts/editor/"
EDITOR=(
"init.js"
"utils.js"
"validation.js"
"main.js"
"menu.js"
"graph.js"
"settings.js"
"interview.js"
"list.js"
"thumbnail.js"
)
# go through each javascript file that has changed and run it rhough JSLINT
for file in $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P '\.((js)|(json))$'); do
if ! node $JSLINT $file 2>&1 | grep ${file}' is OK.' ;
then
node $JSLINT $file
exit 1
fi
done
# Erase old
> $JS_TEMP_EDITOR
> $JS_COMBINED_EDITOR
#run thru the EDITOR and cat the files into one
for editor_file in ${EDITOR[@]}; do
cat "$BASE/$editor_file" >> $JS_TEMP_EDITOR
done
# check if UGLIFYJS gives us an error
if node $UGLIFYJS $JS_TEMP_EDITOR 2>&1 | grep 'Error' ;
then
exit 1
else
# *** THIS IS WHERE THE ERROR IS THROWN
"node $UGLIFYJS -o $JS_COMBINED_EDITOR $JS_TEMP_EDITOR"
fi
exit 0
这是我得到的错误:
.git/hooks/pre-commit: line 55: node /home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /home/john/Projects/node/test/public/javascripts/editor.min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js: No such file or directory
我已将所有文件的权限更改为777仅用于测试,并且还在任何地方检查了CR,我仍然收到错误。奇怪的部分是当我运行命令时,从给出的错误中,我没有问题!
node /home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o /home/john/Projects/node/test/public/javascripts/editor.min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js
工作得很好。
希望有人可以看到我无法看到的东西。
答案 0 :(得分:0)
你可能想要:
node "$UGLIFYJS" -o "$JS_COMBINED_EDITOR" "$JS_TEMP_EDITOR"
否则你告诉bash在路径“/home/john/Projects/node/uglify/node_modules/.bin/uglifyjs -o / home / john / Projects / node / test / public / javascripts / editor中执行二进制文件。 min.js /home/john/Projects/node/test/generated/tmp/_combined_editor.js“这正是错误信息所说的但可能有点令人困惑,因为错误信息不包括引号,只是使用了在论证解析期间。因此,在这种情况下,bash最终会看到一个只有一个参数(要执行的程序的路径)的命令,该命令很长且不存在。