Skip to content
Advertisement

Bash inline version of piping file to bluetoothctl

bt.sh

#!/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.

# ./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:

echo -e 'scan on' | bluetoothctl && sleep 2 && echo -e 'devicesn' | bluetoothctl && echo -e 'quitn' | bluetoothctl;

Advertisement

Answer

Use a command list:

{   printf 'scan onnn'
    sleep 2
    printf 'devicesnn'
    printf 'quitnn'
} | bluetoothctl
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement