I’m using Manjaro Linux. I’ve changed my yt-dlp’s zsh configuration and now I get

❯ ytvp
deal_with_long_filename:1: command not found: xsel -ob
deal_with_long_filename:2: command not found: xsel -ob

The log shows

Usage: yt-dlp [OPTIONS] URL [URL...]

yt-dlp: error: no such option: --continue
  --no-overwrites
  --no-post-overwrites
  --verbose
  --restrict-filenames
  --retry-sleep fragment:exp

Usage: yt-dlp [OPTIONS] URL [URL...]

yt-dlp: error: no such option: --continue
  --no-overwrites
  --no-post-overwrites
  --verbose
  --restrict-filenames
  --retry-sleep fragment:exp

Why is it treating all options as a single one?

I’ve tried running the xsel -ob command on its own and it works fine.

How do I fix this?

I would like to keep the send to background & option that I was using. Would it give problems with the definition of the function deal_with_long_filename?

This is my configuration now

opts="--continue
  --no-overwrites
  --no-post-overwrites
  --verbose
  --restrict-filenames
  --retry-sleep fragment:exp=2:64
  --print-to-file"

if [ -f /usr/local/bin/youtube-dl ]; then
  yt_dlp="/usr/local/bin/yt-dlp"
else
  yt_dlp="$(which yt-dlp)"
fi

# If using Mac
if [[ "$(uname -a | awk '{print $1}')" == "Darwin" ]]; then
  paste="pbpaste"
  opts="${opts} --ffmpeg-location /usr/local/bin/ffmpeg"
else # If using Linux
  paste="xsel -ob"
fi

sanitize_linux_filename() {
  echo "$1" | sed -e 's/[^a-zA-Z0-9._-]/_/g'
}

get_log_name() {
  TIMESTAMP=$( date +%y%m%d%H%M%S )
  NAME=$( sanitize_linux_filename "$1" )
  echo "yt-dlp_${TIMESTAMP}_${NAME}.log"
}

deal_with_long_filename() {
  if ! $yt_dlp $opts --output "%(upload_date>%Y-%m-%d|)s%(upload_date& |)s%(title)s-%(id)s.%(ext)s" "$($paste)" >> "/tmp/$LOG_NAME" 2>&1; then
    $yt_dlp $opts --output "%(upload_date>%Y-%m-%d|)s%(upload_date& |)%(webpage_url_domain)s-%(id)s.%(ext)s" "$($paste)" >> "/tmp/$LOG_NAME" 2>&1
  fi
}

# Video Playlist
ytvp() {
  LOG_NAME=$( get_log_name "$1" )
  opts="${opts}
    --format '(bv+(wa[abr>=64]/ba))/b'
    --format-sort res:720,tbr~2000
    --no-playlist
    --download-archive 'downloaded.txt'"
    
  deal_with_long_filename "$1" "$LOG_NAME"
}