0

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"
2
  • How about to "force" a filename with "-O filename.ext" ? Commented Jul 28, 2020 at 2:12
  • I want to keep the original filenames. I don't see any way to do it that way without downloading twice. Commented Jul 28, 2020 at 2:20

1 Answer 1

0

This works and saves file correctly.

#!/bin/bash
if [ "$#" -eq 0 ]
then
    echo "no argument supplied"
else
    echo "$# arguments:"
    for x in "$@"; do
        new_file=$(wget --content-disposition -nv "$x" 2>&1 |cut -d\" -f2)
        mediainfo "$new_file"
    done
fi

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.