I don't think you want to do what you're asking to do. If all you want is the output of one command used as the argument of another command, then structures like $(...)
or `...`
are your friend. For example:
sudo python ~/testsite/manage.py runserver $(hostname -I):80
Note that this is NOT what you asked for, but it does what you want.
If you really want stdin (a pipe) to be used as an argument, you may be able to use xargs(1) or a quick while
loop in your shell.
This puts stdin at the end of the line:
echo Hello | xargs echo "The word is:"
or if you want to substitute something inside the line:
echo Hello | xargs -J % echo % is the word.
But xargs can be tricky to use if you're not able to understand its (somewhat arcane) usage. The xargs command also varies from OS to OS; the -J
option works in BSD and OSX, but not in some older Linux distros. I don't know what OS you are using.
A loop might be easier:
echo Hello | while read word; do echo "$word is the word."; done
Or in your case:
hostname -I | while read ip; do
sudo python ~/testsite/manage.py runserver ${ip}:80
done
The loop only gets run once, but you can put together your command line a little more easily. YMMV.
sudo python ~/testsite/manage.py runserver "$(hostname -I)"
– jordanm Nov 18 '15 at 14:43"$(hostname -I)"
? For me,hostname -I
returns an IPv4 and an IPv6 address. I have made a command to cut out the IPv6. Can I attach that to thehostname -I
command? – Colby Gallup Nov 18 '15 at 15:07sudo python ~/testsite/manage.py runserver "$(hostname -I | your_custom_command)"
just fine – Dmitry Grigoryev Nov 18 '15 at 16:45hostname -i
returns the localhost IP for me. – Colby Gallup Nov 18 '15 at 16:56