Inspected a character on a particular position in a word
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The problem I personally have with parameter expansion for variables is that it is generally limited and certainly non-intuitive for new users. And once you need slightly more complex patterns, it becomes unwieldy. It uses only a limited form of filename patterns, and doesn't behave as one might expect:
Code:
$ DISK=/dev/sda22
$ echo ${DISK#/dev/*a}
22
$ echo ${DISK#/dev/[a-z]} # OK, a-z char range matches
da22
$ echo ${DISK#/dev/[a-z]*} # What! Ok, maybe longer form...
da22
$ echo ${DISK##/dev/[a-z]*} # Hmmm, that's not what I want either
$ echo ${DISK#/dev/[a-z][a-z][a-z]} # Good, but forces 3 chars in pattern
22
$ echo ${DISK#/dev/[a-z][a-z][a-z]*} # What! Same as above.
22
$ echo ${DISK##/dev/[a-z][a-z][a-z]*} # Nope. How do I say "all but last n digits" ?
$
... but I think one shouldn't have to think hard, worrying about searching the code for finding various oddities like :8:4, which are very specific to only certain devices types. For example, the solution offered doesn't work for devices with varying pattern lengths. Assume we want to find the unit number for either raidNN or sdaNN:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.