我在一个bash脚本中看到了这一行代码:data=$(cat)
,它只是声明一个空变量,但我不知道它到底是干什么的。
我阅读了man手册,但它没有对此进行示例或解释。这是捕获stdin还是其他什么东西?有关此的任何文档资料吗?
编辑:具体来说,做data=$(cat)
如何允许运行此钩子脚本?
#!/bin/bash
# Runs all executable pre-commit-* hooks and exits after,
# if any of them was not successful.
#
# Based on
# http://osdir.com/ml/git/2009-01/msg00308.html
data=$(cat)
exitcodes=()
hookname=`basename $0`
# Run each hook, passing through STDIN and storing the exit code.
# We don't want to bail at the first failure, as the user might
# then bypass the hooks without knowing about additional issues.
for hook in $GIT_DIR/hooks/$hookname-*; do
test -x "$hook" || continue
echo "$data" | "$hook"
exitcodes+=($?)
done
https://github.com/henrik/dotfiles/blob/master/git_template/hooks/pre-commit