I want to be able to download and process a downloaded file with a single command from within a bash script. The filename should be saved with original filename.
I may be going about this all wrong, but how do I get new filename downloaded by wget as a variable?
For example: process.sh "https://demo.io/files.php?action=download&id=123456"
#!/bin/bash
if [ "$#" -eq 0 ]
then
echo "no argument supplied"
else
echo "$# arguments:"
for x in "$@"; do
wget --content-disposition "$x"
mediainfo "$new_file"
done
fi
I found a similar question that has one unaccepted answer that gets close as it produces the correct filename as an output. They suggest:
wget --content-disposition -nv "https://demo.io/files.php?action=download&id=123456" 2>&1 |cut -d\" -f2
However, when I try to put it into a variable like this, it fails.
...
new_file=$(wget --content-disposition -nv "$x" 2>&1 |cut -d\" -f2)
echo $new_file
mediainfo $new_file"