linux – Unix:猫本身做什么?

我在一个bash脚本中看到行数据= $(cat)(只是声明一个空的变量),并且对这可能做什么感到神秘.

我阅读手册页,但没有一个例子或解释.这是否捕获标签?任何有关这方面的文件

编辑:具体如何做数据= $(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

解决方法

猫会输出输出.

在您发布的变量捕获的上下文中,效果是将语句(或包含脚本)的标准输入分配给变量.

命令替换$(command)将返回命令的输出;该赋值会将替换的字符串分配给变量;在没有文件名参数的情况下,cat将会读取和打印标准输入.

您发现这个Git钩子脚本从标准输入捕获提交数据,以便可以分别重复地将其连接到每个钩子脚本.你只得到一个标准输入的副本,所以如果你需要多次,你需要捕获它. (我将使用一个临时文件,并且正确地引用所有的文件名变量;但是将数据保存在一个变量当然可以,尤其是如果你只需要相当少的输入.)

相关文章

Linux中的ARP防火墙主要用于防御ARP欺骗攻击,其效果取决于多...
insmod和modprobe加-f参数导致Invalid module format错误 这...
将ArchLinux安装到U盘 几个月前入门Arch的时候上网搜了不少安...
1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...