Results 1 to 3 of 3

Thread: Bash strange if-behavier with hcitool

  1. #1
    Join Date
    Jul 2012
    Beans
    7

    Bash strange if-behavier with hcitool

    Hello ubuntu-community, i wanted to write a small own bluetooth connector. But i noticed a strange behavier when i scan for bluetooth devices. Here the code:

    Code:
    #!/bin/bash
    
    ArrayCounter=0
    
    while [ 0 -eq 0 ]
    do
        clear
        ScanResult=`hcitool scan`
        #ScanResult=`ls`
        if [ $ScanResult ]
        then
            echo ${ScanResult[0]}
        fi
        sleep 10
    done
    If I use it in the way above, it complains about:
    Code:
    ./bluetoothscan.sh: Zeile 10: [: Zu viele Argumente.
    If i do the same with the command "ls" it workes quite expacted right. Does anyony realize a failure I made?

    Thanks

    mirrowwinger

  2. #2
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

  3. #3
    Join Date
    Sep 2008
    Location
    Windsor,CT
    Beans
    533
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Bash strange if-behavier with hcitool

    Code:
    #!/bin/bash
    
    while true; do
        clear;
        output=$(/usr/bin/hcitool scan | /bin/grep -v "Scanning ...");
        
        if [ ! -z "${output}" ]; then
    	while read baddr devname; do
    	    echo -e "Device Name: ${devname}\t Device Bluetooth Address: ${baddr}"
    	done <<< "${output}"
        fi
        sleep 10
    done

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •