저해상도 미디어 파일 목록이 포함된 파일을 생성하기 위해 다음 코드를 작성했습니다.
#!/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
쉘 코드가 포함된 문자열을 실행하는 데 사용됩니다. 의 출력은 ffprobe
코드가 아닙니다.