I am using a small program written by someone else in bash that runs according to cron on my Synology NAS and basically it does search for subtitles for my movies collection and convert their encoding to utf8 if needed.
In general the main bash script calls another subscripts, and unfortunetly it doesn't work 100% as it should. During my investigation I have narrowed down the problem being this specific function in one of the subscripts:
subs_getCharset_SO() {
local file="$1"
local charset=
local et=
tools_isDetected "file" || return $G_RETFAIL
et=$(file \
--brief \
--mime-encoding \
--exclude apptype \
--exclude tokens \
--exclude cdf \
--exclude compress \
--exclude elf \
--exclude soft \
--exclude tar \
"$file" | wrappers_lcase_SO) || {
return $G_RETFAIL
}
case "$et" in
*utf*) charset="UTF8";;
*iso*) charset="ISO-8859-2";;
us-ascii) charset="US-ASCII";;
csascii) charset="CSASCII";;
*ascii*) charset="ASCII";;
*) charset="WINDOWS-1250";;
esac
echo "$charset"
}
It turns out that running the file command on every movie file causes always a Segmentation fault. I have reproduced it by running this command in terminal manually:
admin@Synek:/volume1/video/Filmy/Ghostland.2018$ file --brief --mime encoding Ghostland.2018.txt
The output is:
utf-8
Segmentation fault
So my main problem as I think is that the output of the file
command is not assigned to et
variable. My goal ideally would be to capture the first line of the output and assign it to et
variable. Or at least redirect the output to a file, so far I have tried some solutions that I have found in the web:
admin@Synek:/volume1/video/Filmy/Ghostland.2018$ { file --brief --mime-encoding ./Ghostland.2018.txt; } 2> log
which outputs in terminal just the line that I need and omits the Segmentation fault message:
utf8
Running:
admin@Synek:/volume1/video/Filmy/Ghostland.2018$ cat log
Gives:
Segmentation fault
But I just can't find a way to get the first line before Segmentation fault written in the log output file.
Any help appreciated!