What does this code mean?
surfrock66 opened this issue · 3 comments
I didn't know where to ask a question like this; I'm looking at simple-dlna-browser and I don't understand a piece of syntax, on line 246 what does the following snipped do?
"${@:-0}"
I know it's indexing something in the array of passed arguments to the function, but is -0 the number of elements or something? Is it all the arguments together?
Hi,
Yep, the syntax means, if no parameters are left in the $@ array after using the first 3, then a '0' is used, hope this helps somehow.
Awesome, thanks! I'm doing some experimenting on making directories navigable as my dlna setup relies heavily on folder structure.
I didn't want to fork the whole repository for this, but my first dirty edit to this replaces lines 367-373 and allows you, with the verbose flag, to browse folders from the CLI. This is a very dirty first effort:
if [[ "${@}" -ge 0 ]] 2> /dev/null
then
choice="${@}"
else
choice=0
fi
while [ "$choice" != "99" ]; do
_list_media "${server}" "${port}" "${verbose_lvl}" "${choice}" || {
case "${?}" in
127) _die "Specify a dlna media server" \
"or install 'socat' to enable autodetection." ;;
*) _die "No dlna media server found at: ${server}:${port}"
esac
}
read -p "Please select the directory to browse (99 to exit): " choice
done