Skip to main content
add example for using ksh93 backreference
Source Link
Mikel
  • 58.7k
  • 16
  • 136
  • 155

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.

 

(Apparently UPDATE

Apparently back references may beare supported in ksh93).

So you could use something like

FILE="${FILE/@(.*)/_something\1}"

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.

(Apparently back references may be supported in ksh93)

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.

 

UPDATE

Apparently back references are supported in ksh93.

So you could use something like

FILE="${FILE/@(.*)/_something\1}"
added 119 characters in body
Source Link
Mikel
  • 58.7k
  • 16
  • 136
  • 155

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.

(Apparently back references may be supported in ksh93)

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.

(Apparently back references may be supported in ksh93)

Source Link
Mikel
  • 58.7k
  • 16
  • 136
  • 155

Bash Parameter Expansion says that the variable (FILE in your example) must be a parameter name. So they don't nest. And the last part of ${param/pattern/replacement} must be a string. So back references aren't supported.

My only advice is to use

${EXT:+.$EXT}

to avoid adding a trailing dot if the file has no extension.