我编写了以下代码,旨在创建一个包含低分辨率媒体文件列表的文件:
#!/usr/bin/bash
find "$PWD" -type f -iname "*.avi" -execdir ~/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh {} + >~/pCloudDrive/VisualArts/lowres.films
find "$PWD" -type f -iname "*.mkv" -execdir ~/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh {} + >>~/pCloudDrive/VisualArts/lowres.films
find "$PWD" -type f -iname "*.mp4" -execdir ~/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh {} + >>~/pCloudDrive/VisualArts/lowres.films
正如您所看到的,上面的代码printer.sh
调用了以下代码:
#!/usr/bin/bash
#The script is meant to print only the results of low resolution, that is starting with 1, 2, 3, 4, 5
if [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 2* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
elif [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 3* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
elif [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 4* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
elif [[ $(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1) == 5* ]]; then
echo "$(realpath $1)" && ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1
fi
想要用我修改的变量替换代码中的重复printer.sh
:
#!/usr/bin/bash
output=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $1)
if [[ $($output) == 2* ]]; then
echo "$(realpath $1)" && eval "$output"
elif [[ $($output) == 3* ]]; then
echo "$(realpath $1)" && eval "$output"
elif [[ $($output) == 4* ]]; then
echo "$(realpath $1)" && eval "$output"
elif [[ $($output) == 5* ]]; then
echo "$(realpath $1)" && eval "$output"
fi
现在它不起作用,我得到的输出如下所示:
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 6: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 8: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 10: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 12: 1920x1024: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 6: 1920x800: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 8: 1920x800: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 10: 1920x800: command not found
/home/jerzy/CS/SoftwareDevelopment/MySoftware/Bash/lowresolution_finder/printer.sh: line 12: 1920x800: command not found
我做错了什么?我应该如何重写它?
答案1
看起来你想要的是这样的:
output=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$1")
if [[ $output == [2345]* ]]
then
echo "$(realpath "$1")" "$output"
fi
我eval
根本不知道你为什么用这里。eval
用于执行包含 shell 代码的字符串。的输出ffprobe
不是代码。