bash - BASH:使用管道创建变量
问题描述
我有一个 bash 文件,它希望在某个目录中查找早于某个日期的文件并将其删除。它工作正常,我能够回显已删除文件的数量,但是当我尝试将整数放入变量时遇到问题。
#!/bin/bash
# Make this dynamic to look at different directories.
pathtofolder=/var/www/website/temp2/
if [ $hours ]; then
# To specify older than one day it is better to talk in hours because
# the days integer is just an integer so everything less than 2 days
# would be 1 day, so 1 day 23 hours and 59 minutes is not greater than
# 1 day.
# For this reason I am using mmin and using the hours in minutes.
timeinmins=$(($hours*60))
elif [ $mins ]
then
timeinmins=$mins
else
# The default is 24 hours but we want to test with 24 minutes
timeinmins=24
fi
find "$pathtofolder"* -mmin +$timeinmins -exec rm -vr {} \; | output="$(wc -l)"
echo "Files deleted: $output"
echo "Minutes: $timeinmins"
在上述情况下,$output
为空白。
但这在下面起作用,只是为了回声......
find "$pathtofolder"* -mmin +$timeinmins -exec rm -vr {} \; | "Files deleted: $(wc -l)"
有任何想法吗?提前致谢。
解决方案
推荐阅读
- caffe - 为什么尝试在 Jetson TX2 上运行 nvidia 的教程代码时,图层权重为空且 TRT 找不到缓存?
- python - 从二维列表中给定相同坐标的列表中选择最小值
- javascript - 如何启动 react-native onTouchDown anination
- php - 如何从数组键和值中删除双引号?
- java - 使用java从嵌套的JSON对象中读取数据
- presto - 无法使用自定义密码验证器通过 https 启动 prestodb 服务器
- r - 用 dplyr 重写基本 R 函数 - 使用过滤器而不是 []
- google-maps-android-api-2 - 谷歌地图的自定义信息窗口在Android中不渲染高程阴影
- javascript - 如何获取哪个集群获取了请求。PM2 簇
- python-3.x - Python handlers.TimedRotatingFileHandler 旋转无法按预期工作