Click here to Skip to main content
11,705,473 members (56,521 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux
I am developing a USB tree based application on a Linux operating system for that I am converting one of the shell script to C++. But I am not that much experienced in shell script

I am confused in this script

if [ $level -gt 0 ]; then
        port=$((${devpath##*[-.]} - 1))
    else
        port=0
    fi

Any one please explain me the meaning of this script in usb-devices script in linux. How I can write a C/C++ code to equivalent of this. i am stuck in this $((${devpath##*[-.]} - 1)) line of script


Any help will be appreciated...
Posted 19-Feb-13 20:14pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is parameter substitution using pattern matching as described in the ksh man pages[^]. It's a while since I wrote scripts but it appears to be looking for a string of the form devpath followed by zero or more characters, followed by a hyphen or a dot. The resulting value is decremented by 1 before being set into the variable port.

Note: I'm not 100% certain of my analysis here, experimentation should help to clarify it.
  Permalink  
Comments
Arun Kumar K S at 20-Feb-13 23:13pm
   
Many thanks that link helped me to solve the issue....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 286
1 OriginalGriff 269
2 ppolymorphe 78
3 Inimicos 60
4 ProgramFOX 50
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100