bt.sh
JavaScript
x
#!/bin/bash
echo -e 'scan onn'
sleep 2
echo -e 'devicesn'
echo -e 'quitn'
If I pipe the above file to bluetoothctl, it works as expected.
JavaScript
# ./bt.sh | bluetoothctl
But how can I do that as an inline script, I have tried the following but it does not work and bluetoothctl does not appear to register the commands:
JavaScript
echo -e 'scan on' | bluetoothctl && sleep 2 && echo -e 'devicesn' | bluetoothctl && echo -e 'quitn' | bluetoothctl;
Advertisement
Answer
Use a command list:
JavaScript
{ printf 'scan onnn'
sleep 2
printf 'devicesnn'
printf 'quitnn'
} | bluetoothctl