linuxvariable-substitution

Embedded parameter substitution


This is what parameter substitution would be one by one (transforming a picture file name into a date) :

var=“2020-12-30 11-30-55CX.mov”
p1=${var:0:11}
pt=${var:11:8}
p2=${pt//-/:}
dt=“${p1} ${p2}”

I want to do this in one shot, something like this so exiftool can take it:

dt=“${var:0:11} ${${var:11:8}//-/:}”

Solution

  • You can't nest expansion operators like that. But you can just work with smaller substrings to get the result you want.

    dt="${var:0:11} ${var:11:2}:${var:14:2}:${17:2}"