![스크립트가 bluetoothctl에서 명령을 실행하지 않습니다.](https://linux55.com/image/166413/%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EA%B0%80%20bluetoothctl%EC%97%90%EC%84%9C%20%EB%AA%85%EB%A0%B9%EC%9D%84%20%EC%8B%A4%ED%96%89%ED%95%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4..png)
Bluetooth 헤드폰을 Linux 시스템에 자동으로 연결하는 작은 스크립트를 작성했습니다.
#!/bin/bash
bluetoothctl
wait ${!}
connect XX:XX:XX:XX:XX:XX #headphone MAC address
wait ${!}
exit
스크립트가 열리지 bluetoothctl
만 다음 명령은 실행되지 않습니다.
답변1
bluetoothctl
다음과 같이 쉘 스크립트에서 명령을 사용할 수 있습니다 .
bluetoothctl -- command
또는:
echo -e "command\n" | bluetoothctl
예를 들어:
bluetoothctl -- connect XX:XX:XX:XX:XX:XX
답변2
bluetoothctl -- pair XX:XX:XX:XX:XX:XX
sleep 10
bluetoothctl -- trust XX:XX:XX:XX:XX:XX
bluetoothctl -- connect XX:XX:XX:XX:XX:XX
sleep 5
기적적으로 작동합니다. pair
BT 장치를 검색하고 설정할 수 있는 시간을 허용하기 위해 "절전" 지연을 추가할 때 특히 유용합니다 .trust
connect
bluetoothctl
그것은 마치
bluetoothctl <<EOF
pair XX:XX:XX:XX:XX:XX
sleep 10
exit
EOF
sleep
에서 명령으로 인식되지 않기 때문에 작동하지 않습니다 bluetoothctl
.