E.g. check if $PWD is a subdirectory of /home. In other words I'm searching for a bash string operation to check if one string starts with another.
|
|
|
How about this:
If |
|||
|
|
To test if a string is a prefix of another, in any Bourne-style shell:
The same principle works for a suffix or substring test. Note that in In shells that implement the
If you're specifically testing whether the current directory is underneath If
If you have the NetBSD, OpenBSD or GNU (i.e. Linux)
Otherwise, you can use
|
||||
|
|
Crude version:
Has the disadvantage that one has to count characters first and one can't replace edit (thanks @Michael) for the generalization to compare with
|
|||||||
|
|
Using
|
|||
|
|
|
I don't understand the question too well, but to find the parent of $PWD, do |
|||||
|
|
Hm, it's pity that You may try
|
|||
|
|
|
If the searched part of path is found I "empty" the variable :
|
|||
|
|
