At the moment I have two scripts, one for files and one for urls and I want to combine them.
The below script is combined. When an argument is passed, I want it to perform one function if it is a url, and another if it is a file that is passed as an argument. Sometimes I will pass multiple files using a wildcard.
I use @Q in order to escape special characters. In my particular case quotes fail.
At the moment when I run it, both functions are performed and I can't figure out the correct arrangement.
Example1: script.sh "https://demo.io/download.php?id=123456"
Example1: script.sh "http://test.io/download.php?id=54321"
Example3: script.sh "John's file.mp4"
Example4: script.sh "John's file*.mp4"
#!/bin/bash
if [ "$#" -eq 0 ]
then
echo "no argument supplied"
else
if [[ $1 != http?(s):// ]]; then
echo "Invalid URL, must be a file"
echo "$# arguments:"
for x in "$@"; do
foo_esc="${x@Q}"
echo "file is "$foo_esc""
mediainfo "$foo_esc"
done
fi
echo "$# arguments:"
for y in "$@"; do
file=$(wget --content-disposition -nv "$y" 2>&1 |cut -d\" -f2)
echo "output is "$file""
mediainfo "$file"
done
fi