#!/usr/bin/env bash cur="" function output { exec echo ''"$1"'' } if [ -d /sys/class/bluetooth ] ; then bluetoothctl -- info | while read line ; do key=${line%%: *} value=${line//*: } if [ "$key" == "Name" ] ; then cur="$value" fi if [ "$key" == "Connected" -a "$value" == "yes" ] ; then output "$cur " fi done fi output " "