How to pass the output of one command as the command-line argument to another?

  • So I have a script that, when I give it two addresses, will search two HTML links:

    echo "\=$1\&daddr\=$2" | sed 's/ /%/g'

    I want to send this to wget and then save the output in a file called temp.html. I tried this, but it doesn't work. Can someone explain why and/or give me a solution please?

    url = echo "\=$1\&daddr\=$2" |  sed 's/ /%/g'
    wget $url

    For debugging something like this checking your variable values (by echo-ing them to the terminal) often gets you to the solution quickly.

  • You can use backticks (`) to evaluate a command and substitute in the command's output, like:

    echo "Number of files in this directory: `ls | wc -l`"

    In your case:

    wget `echo\=$1\&daddr\=$2 | sed 's/ /%/g'`

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM