M
M
m2_viktor2015-06-04 13:02:21
linux
m2_viktor, 2015-06-04 13:02:21

How to execute a command in Linux with a parameter taken from the stdout of the previous command?

Hello, I got confused by this question after I wanted to wake up my home computer using etherwake by sending a magic-packet to the mac-address of the computer. Since I don't remember the mac-address by heart, I took it from /etc/config/dhcp
with tail -n2 /etc/config/dhcp | head-n1 | tr -s " " | tr -d \' | cut -f3 -d " "
Got a mac in stdout, but how do I substitute it? etherwake -i br-lan "my mac address".

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
egor_nullptr, 2015-06-04
@m2_viktor

ваша команда получения мака | xargs etherwake -i br-lan

S
Sergey, 2015-06-04
Protko @Fesor

MY_MAC=$(tail -n2 | head -n1 | tr -s " " | tr -d \' | cut -f3 -d " ")
etherwake -i br-lan "$MY_MAC"

N
Nikolay Shamanovich, 2015-06-04
@Shm13

etherwake -i br-lan `ваша команда получения мака`
or
In the first case, everything in dashes will first be replaced by the result of the script, in the second case, a new variable will be created.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question