Click here to Skip to main content
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 OriginalGriff 371
1 Sergey Alexandrovich Kryukov 269
2 CB Sharma 79
3 RyanDev 75
4 PhilLenoir 70
0 Sergey Alexandrovich Kryukov 6,676
1 OriginalGriff 6,056
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
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