I have a file name (including an extension, but not a full path name)
in variable file
, and I want to only get the last 10 characters of the base name from a parameter expansion.
Example: file
contains the filename A_text_document_1234567890.txt
.
Desired output: 1234567890
.
I know that I can use ${file%.*}
to remove the extension: echo ${file%.*}
outputs A_text_document_1234567890
.
If I do base=${file%.*}
, then I can use ${base: -10}
to get 1234567890
.
Can I do this inside the parameter expansion all in one step
without using a second variable?
I guess my real question is, how do I combine these two parameter expansions into one?
Parameter Expansion
the question is misleading... which has answered on some post here. – Jetchisel Feb 26 '20 at 23:49${var:off:len}
form, with"${file#"${file%??????????}"}"
– Feb 27 '20 at 11:22${file: -10}
. – Feb 27 '20 at 17:51.txt
, the solution in bash/ksh/zsh is obviously"${file: -14:10}"
;-) – Feb 27 '20 at 18:02