Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here I want to know about this sdptool command does in the following script snippet:

if [ `sdptool browse $BD_ADDR | wc -l` -lt 5 ]

I understand sdptool browse $BD_ADDR as well as wc -l -- it's used for new line counts in result of sdptool browse $BD_ADDR.

but what about -lt 5?

share|improve this question

migrated from stackoverflow.com Jan 23 '12 at 18:15

This question came from our site for professional and enthusiast programmers.

4 Answers 4

-lt 5 means "lesser than 5".

So the if body will execute if sdptool returns less than 5 lines.

share|improve this answer
    
here in C How can i store return value of 'sdptool browse $BD_ADDR | wc -l'. i am using system call so system call return 0 on success but how can i store word count return value so i will compare with less than 5 –  user1089679 Jan 23 '12 at 6:41
    
See the popen function. –  Cicada Jan 23 '12 at 6:43
2  
Alternatively you could system("sdptool browse $BD_ADDR | wc -l > output.txt"); and then read output.txt with fopen. –  Cicada Jan 23 '12 at 6:45
    
popen return the output of this command? –  user1089679 Jan 23 '12 at 6:48
    
popen is return the I/O Strem of this process but i have to read that value so may be its not useful. –  user1089679 Jan 23 '12 at 6:50

Here is the breakdown of

if [ `sdptool browse $BD_ADDR | wc -l` -lt 5 ]
  1. if: the beginning of a shell if-statement
  2. [: this is actually a command. It is an alias for the test command
  3. `: this is the beginning of command substitution
  4. sdptool browse $BD_ADDR | wc -l: returns the number of lines output by sdptool
  5. `: the end of the command substitution
  6. -lt 5: this is an argument to the test command mentioned earlier. The output of the command substitution (the number of lines output by sdptool) is compared to 5 and returns true if less-than or false otherwise
share|improve this answer
    
here in C How can i store return value of 'sdptool browse $BD_ADDR | wc -l'. i am using system call so system call return 0 on success but how can i store word count return value so i will compare with less than 5 –  user1089679 Jan 23 '12 at 6:42
    
you will want to use popen() and pclose() which returns a FILE * to a pipe that runs the commands you pass in. You could then use something like fgets() to read that FILE * into a character buffer –  SiegeX Jan 23 '12 at 6:49
    
can i not use if(a=system("sdptool browse $BD_ADDR | wc -l > output.txt") < 5) ? –  user1089679 Jan 23 '12 at 6:55
1  
man 3 system and read what the return value is. It is not the output of the command being run –  SiegeX Jan 23 '12 at 7:03
    
ok thanx so i have to compulsary use popen –  user1089679 Jan 23 '12 at 7:11

[ is the unix command test, see the documentation man test. The option -lt means

   INTEGER1 -lt INTEGER2

      INTEGER1 is less than INTEGER2

So your command checks whether the number of lines is < 5.

share|improve this answer

The -lt argument to [/test performs an arithmetic comparison of the two arguments around it, returning true if the preceding argument is an integer less than the following argument.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.