Say I have the following file names from an ls in a bash script:
things-hd-91-Statistics.db
things.things_domain_idx-hd-38-Data.db
In bash, how would it be able to get the first part of the string 'things' in either case?
Basically remove the rest of the string past the first - or .
You would use parameter expansion:
Where in
${parameter%%pattern}the ‘pattern’ (-*) is matched against the end of ‘parameter’. The result is the expanded value of ‘parameter’ with the longest match deleted.Similarly for your other example, the pattern would be
%%.*