I am trying to create a shell script for yt-dlp that takes an URL as input from the command line or if no input is given use an internal list. The script works when given input, but crashes when no input is given and thus using the internal list.
#!/usr/bin/env bash
URLfromTerminal="$1"
PathToList="--batch-file '${HOME}/bin/ytdlp/Lists/Test.txt'"
[[ -z "$URLfromTerminal" ]] && Download="$PathToList" || Download="$URLfromTerminal"
yt-dlp -ciw
-S "res:1920"
--ffmpeg-location "$HOME"/bin/ffmpeg/ffmpeg
"$Download"
Error message when no input is given and using the internal list:
yt-dlp: error: no such option: --batch-file '/Users/UserName/bin/ytdlp/Lists/Test.txt'
Why is the path to the text file treated as an option by yt-dlp when expanded from a variable?
I am new to shell scripting and don't know what's best practice, so any general improvement is also welcome.
$Download
yt-dlp gives another error messageERROR: batch file '/Users/UserName/bin/ytdlp/Lists/Test.txt' could not be read
. But that file exists and has content. Is it something wrong with the single quotation marks here? – Kasam Dec 16 '22 at 12:39