Search code examples
linuxbashinline

Bash inline version of piping file to bluetoothctl


bt.sh

#!/bin/bash

echo -e 'scan on\n'
sleep 2
echo -e 'devices\n'
echo -e 'quit\n'

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 'devices\n' | bluetoothctl && echo -e 'quit\n' | bluetoothctl;

Solution

  • Use a command list:

    {   printf 'scan on\n\n'
        sleep 2
        printf 'devices\n\n'
        printf 'quit\n\n'
    } | bluetoothctl