首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较具有整数nto with bash脚本的文件数

比较具有整数nto with bash脚本的文件数
EN

Stack Overflow用户
提问于 2021-04-30 16:49:45
回答 1查看 13关注 0票数 0

我正在编写一个bash脚本来使用FFMpeg处理文件,这取决于文件的数量。

我正在编写一个if / elif语句来检查有多少个文件与一个字符串匹配,但首先去掉字符串末尾的一部分。这种比较似乎行不通,我试过==和-eq。不确定有没有更好的方法来做这件事

代码语言:javascript
复制
#!/bin/bash
#Generate Quads from 4 video files, Trio from 3 and duo from 2

#InputVariables
inputpath=$( pwd | awk -F/ '{ print $0"/" }' )
outputpath=$( pwd | awk -F/ '{ print $0"/" }' ) #TEMP TEST OUTPUT
#outputpath=$( pwd | awk -F/ '{ print "/"$2"/projects/"$5"/Library/Ref/ProcessedWitcam/"$6"/" }' )

#Command Start
if [ "$( echo $inputpath | grep -F witcam )" ]; then
    #Create only 1 instance of this script to avoid clashes
    if [ ! "$(ls /var/run/ | fgrep -i quadGen.pid)" ]; then
        yes no | nice -n 15 touch /var/run/wrangling/quadGen.pid
        echo "PID created"
        for videofile in $(find *_1_BTC.mp4 -type f); do
            if [ "$(ls $outputpath | fgrep -i ${videofile%_1_BTC.mp4}.mp4)" ]; then
                echo "Converted $videofile Already"
            else
                echo find "${videofile%_1_BTC.mp4}"* | wc -l
                if [ "find ${videofile%_1_BTC.mp4}* | wc -l" == 5 ]; then
                    echo "QUAD GEN"
                    timecode=$( ffmpeg -i "$videofile" 2>&1 | awk '$1 ~ /^timecode/ {print $NF}' | uniq  )
                    ffmpeg -i ${videofile%_1_BTC.mp4}_2.mxf -i $videofile -i ${videofile%_1_BTC.mp4}_3.mxf -i ${videofile%_1_BTC.mp4}_4.mxf -filter_complex "[0:v][1:v]hstack[top]; [2:v][3:v]hstack[bottom]; [top][bottom]vstack,format=yuv420p[v]"  -map "[v]"  -ac 2 -flags global_header -timecode $timecode -c:v libx264  $outputpath/${videofile%_1_BTC.mp4}.mp4
                elif [ "find ${videofile%_1_BTC.mp4}* | wc -l" == 4 ]; then
                    echo "TRIO GEN"
                    timecode=$( ffmpeg -i "$videofile" 2>&1 | awk '$1 ~ /^timecode/ {print $NF}' | uniq  )
                    ffmpeg -i ${videofile%_1_BTC.mp4}_2.mxf -i $videofile -i ${videofile%_1_BTC.mp4}_3.mxf -filter_complex "[0:v][1:v][2:v]hstack=inputs=3[v]"  -map "[v]"  -ac 2 -flags global_header -timecode $timecode -c:v libx264  $outputpath/${videofile%_1_BTC.mp4}.mp4
                elif [ "find ${videofile%_1_BTC.mp4}* | wc -l" == 3 ]; then
                    echo "DUO GEN"
                    timecode=$( ffmpeg -i "$videofile" 2>&1 | awk '$1 ~ /^timecode/ {print $NF}' | uniq  )
                    ffmpeg -i ${videofile%_1_BTC.mp4}_2.mxf -i $videofile  -filter_complex "hstack" -ac 2 -flags global_header -timecode $timecode -c:v libx264  $outputpath/${videofile%_1_BTC.mp4}.mp4
                else
                    echo "Error: incorrect number of files"                 
                fi
            fi
        done
        yes no | nice -n 15 rm -f /var/run/wrangling/quadGen.pid
    fi
fi

这部分:

代码语言:javascript
复制
echo find "${videofile%_1_BTC.mp4}"* | wc -l

这是正确的,因为我得到了一个值,我不知道如何正确地比较它

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-30 16:59:34

双引号引入一个字符串,而不是要运行的命令。不要使用它们。

请改用命令替换:

代码语言:javascript
复制
if [ $(find ${videofile%_1_BTC.mp4}* | wc -l) == 5 ]; then

你可以在这里同时使用==-eq==比较字符串,-eq比较整数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67330901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档