[英]variable from bash 'if echo grep'
I'm using the following code to sort recordings and captures from my CCTV into dated sub directories that are more than a day old.我正在使用以下代码将我的 CCTV 中的录音和捕获内容分类到超过一天的过时子目录中。
Is there any way to reference the results of the echo grep date
section of the IF
code as a variable so that it can be used when creating a folder?有什么方法可以将
IF
代码的echo grep date
部分的结果引用为变量,以便在创建文件夹时可以使用它?
I could just create a variable on a separate line with another use of grep
(or define the variable and reference it in the IF
statement) but would prefer if it were all on one line.我可以在单独的一行上创建一个变量,并使用
grep
另一种用法(或定义变量并在IF
语句中引用它),但如果它全部都在一行上,我会更喜欢。
File names are similar to 'MDAlarm_20160417-120925.jpg' so the contents of the variable would be 2016-04-17.文件名类似于“MDAlarm_20160417-120925.jpg”,因此变量的内容将是 2016-04-17。
for f in ~/FI9803P_00626E5755DE/**/*;
do
if [[ `echo $f | grep -oP '\d{8}' | date -f - +'%Y-%m-%d'` != `date +'%Y-%m-%d'` ]]; then
mkdir -p $(dirname $f)/$varFromIF; echo "Made it" #mv $f $(dirname $f)/$varFromIF
fi
done
Yes.是的。 You can do it like this:
你可以这样做:
for f in ~/FI9803P_00626E5755DE/**/*;
do
if [[ "${varFromIF=$(echo $f | grep -oP '\d{8}' | date -f - +'%Y-%m-%d')}" != $(date +'%Y-%m-%d') ]]; then
mkdir -p $(dirname $f)/$varFromIF; echo "Made it" #mv $f $(dirname $f)/$varFromIF
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.