tee可以传递输出给管道的同时,输出到文件,我们都知道;但把输出到文件改为输出到屏幕,也是有市场需求的,如下案例
案例2(/dev/tty):
需求,把一个命令的默认输出,显示在屏幕上的同时,传递给后面的管道命
[root@localhost ~]# cat txe
ROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/DepositList.vue
Module not found: Error: Can't resolve 'vue-ctk-date-time-picker' in '/home/ubuntu/deploy/backend/surfaces/src/views'
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/DepositList.vue 7:0-60
[root@localhost ~]# cat txe | tee /dev/tty |grep 'Error:'
ROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/DepositList.vue
Module not found: Error: Can't resolve 'vue-ctk-date-time-picker' in '/home/ubuntu/deploy/backend/surfaces/src/views'
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/DepositList.vue 7:0-60
Module not found: Error: Can't resolve 'vue-ctk-date-time-picker' in '/home/ubuntu/deploy/backend/surfaces/src/views'
衍生品(技巧:if 后面直接跟命令,更高效):
[root@localhost ~]# if cat txe | tee /dev/tty | grep 'xml';then echo ok;else echo no;fi
ROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/DepositList.vue
Module not found: Error: Can't resolve 'vue-ctk-date-time-picker' in '/home/ubuntu/deploy/backend/surfaces/src/views'
@ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/views/DepositList.vue 7:0-60
@ ./src/views/DepositList.vue
@ ./src/router/index.js
@ ./src/main.jld complete.
no
生产脚本(红字部分):
#!/bin/bash
# author: royoy
cd /home/ubuntu/deploy/merchants
git pull || {
echo "first pull failed"
exit 3
}
wait
git checkout master || {
echo "checkout failed"
exit 3
}
wait
git pull || {
echo "second pull failed"
exit 3
}
wait
sleep 6
cd /home/ubuntu/deploy/merchants/surfaces
if npm run build | tee /dev/tty | grep 'Error:';then echo -e "\nnpm build error";exit 1;fi
cd /home/ubuntu/deploy
make merchants || {
echo "make merchants failed"
exit 3
}
wait
sleep 1
cd /home/ubuntu/repos
php deployment.php merchants prod merchant