Bash Shell Command Line – How to Pass the Output of One Command as the Command-Line Argument to Another

bashcommand lineshell

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

echo "http://maps.google.be/maps?saddr\=$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?

#!/bin/bash
url = echo "http://maps.google.be/maps?saddr\=$1\&daddr\=$2" |  sed 's/ /%/g'
wget $url

Best Answer

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 http://maps.google.be/maps?saddr\=$1\&daddr\=$2 | sed 's/ /%/g'`
Related Question