Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

for loop append variable bash 7

i use at the moment this script to find languages from sub files. and this working nice. I would like to expand it.

#!/bin/bash
path=/tmp
name=Test-dir
mkv=test.mkv

RESULTS=""
for i in $(ls -l $path/$name/Subs);do
if [[ $i =~ .*\.idx$ ]];then
tr -d '\r' < $path/$name/Subs/$i > $path/$name/Subs/newfile
rm -f $path/$name/Subs/$i
mv $path/$name/Subs/newfile $path/$name/Subs/$i
results=$(cat $path/$name/Subs/$i |awk '/^# alt:/ { a[$3] } END { for (l in a) { printf("%s%s", c, l); c = " " } printf("\n") }')
RESULTS="$RESULTS$results "
fi
done
echo ${RESULTS%" "}  #Get rid of the trailing space 
#output : English Italian

I want first check is a language forced, i can check this with ouput is "Yes" or nothing "Empty"

forcsub=$(mediainfo --Inform="Text;%Forced%" $path/$name/$mkv)
echo "$forcsub"
#output : Yes or is empty

so can check is witch Language is forced

forelang=$(mediainfo --Inform="Text;%Language/String%" $path/$name/$mkv)
echo "$forelang"
#output : Italian

how can I bring that together? that output so is when no language forced is : English Italian

when a language forced is : Italian Forced, English

Comments