[Discuss] Bash script help

John Blomfield jabfield at shaw.ca
Sun Mar 2 10:15:47 PST 2014


On 03/01/2014 06:58 PM, brendan wrote:
> either of these will work:
>
> adb devices | grep 3230ce87e28a70b9 | awk '{print $1'}

Thanks Brendan the one above works fine but not the one below.

> adb devices | grep 3230ce87e28a70b9 | cut -f1 -d' '

also the one I found on a forum, namely,


DEVICENUM=$(adb devices | grep 3230ce87e28a70b9)
NUM=( $DEVICENUM )
TEMP=${NUM[0]}
if [ "$TEMP" != "3230ce87e28a70b9" ] ; then  echo 'Error' ; else echo 
'OK' ; fi

However, I have never got around to understanding string manipulation in 
Bash so I don't understand how any of the above works. I use Bash just 
occasionally for simple logic scripts without string parsing. If I have 
a more complicated string manipulation problem I use Python, a language 
I understand better, also used infrequently but closer to C/C++ that I 
normally use. So now I have to decide whether or not to write the thing 
in Python, spend time learning more Bash or use C++ which would be 
overkill. The whole thing will probably only need about 50 lines of code 
either way. The way Bash has all those punctuation symbols and brackets 
that mean strange and wonderful things that drives me nuts. Problems! 
Problems!

Thanks again,

John

>
>
> On 14-03-01 12:16 PM, John Blomfield wrote:
>> Ooops some corrections!
>>
>> On 03/01/2014 12:13 PM, John Blomfield wrote:
>>> I want to test that my Android device is connected to my PC usb 
>>> before doing other stuff on the ADT sdk in the script ...............
>>>
>>> ................
>>> adb devices
>>>
>>> #results in
>>> List of devices attached
>>> 3230ce87e28a70b9        device
>>> # if its connect or
>>> List of devices attached
>>>
>>> # an empty list if its not if I run
>>>
>>> adb devices | grep 3230ce87e28a70b9
>>>
>>> # I get
>>> 3230ce87e28a70b9        device
>>>
>>> #How do I extract the number 3230ce87e28a70b9 as a variable 
>>> $DEVICENUM so I can test it in an "if" statement e.g.
>>>
>>> if [ 3230ce87e28a70b9 = $DEVICENUM ] ; then 
>>> ......................more stuff
>>>
>>> Thanks John
>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://lists.vlug.org/mailman/listinfo/discuss
>


-- 
John Blomfield
Delivered by Thunderbird Email on Linux OpenSuse-KDE4

Old John B's Linux Notes http://www.oldjohnbslinux.wordpress.com




More information about the Discuss mailing list