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

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'`

You could use "xargs". A trivial example:

ls -1 *.c | sort -n | xargs cat

You would have to take care that xargs doesn't split its stdin into two or more invocations of the comman ("cat" in the example above).


you're not actually executing your url line :

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