- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 64字
- 2021-07-09 19:46:22
How to do it...
The % operator will extract the name from name.extension. This example extracts sample from sample.jpg:
file_jpg="sample.jpg" name=${file_jpg%.*} echo File name is: $name
The output is this:
File name is: sample
The # operator will extract the extension:
Extract .jpg from the filename stored in the file_jpg variable:
extension=${file_jpg#*.} echo Extension is: jpg
The output is as follows:
Extension is: jpg