我正在尝试将数组作为另一个 bash 文件的输入传递。主文件是:
#!/bin/bash
arr=( "$@" )
path=`pwd`
cd ${arr[0]}
read -p "Enter number of videous: " number_of_videous
for ((i=0;i<number_of_videous;i++))
do
read -p "Enter the resolution: " resolution
if [ $resolution -eq 1080 ]
then
mkdir "${arr[1]}_1080_directory"
ffmpeg -i ${arr[1]} -vf scale=1920:1080 -preset slow -crf 18 "${arr[1]}_1080_directory/output.mp4"
arr=("${arr[1]}_1080_directory/output.mp4" "$resolution")
sh "$path"/check_resolution_video.sh "${arr[@]}"
.~/Script/bitrate.sh "${arr[1]}_1080_directory" "output.mp4"
elif [ $resolution -eq 720 ]
then
mkdir "${arr[1]}_720_directory"
ffmpeg -i ${arr[1]} -vf scale=1280:720 -preset slow -crf 18 "${arr[1]}_720_directory/output.mp4"
arr=("${arr[1]}_720_directory/output.mp4" "$resolution")
.~/Script/check_resolution_video.sh "${arr[@]}"
.~/Script/check_resolution_video.sh "${arr[@]}"
.~/Script/bitrate.sh "${arr[1]}_720_directory" "output.mp4"
fi
done
而必须调用并传递变量的文件是:
#!/bin/bash
echo `pwd`
echo "$@"
arr=("$@")
resolution=`ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x "${arr[0]}"`
if [ ${arr[1]} -eq 1080 ] ; then
if [ $resolution == '1920x1080' ] ; then
echo "The video: ${arr[1]} is true"
fi
elif [ ${arr[1]} -eq 720 ] ; then
if [ $resolution == '1280x720' ]
then
echo "The video: ${arr[1]} is true"
fi
fi
一切正常,直到第二个文件的“arr=("$@")”。这不是权限问题。
错误为:“/home/alex/Script/check_resolution_video.sh:7:语法错误:“(”意外“。
此外,由于我首先回显了这些参数,因此脚本收到了正确的参数。
你知道在这种情况下我该怎么办吗?