views:

35

answers:

1

Hi,

Could anyone eloborate how ##*/ works in UNIX Shell scripting. I have seen it's use in Korn Shell. It is specifically used for removing extension of file.

e.g. func_write_app_log "o Deleting status file ${CIE_STATUS_FILE##*/}"

Here suppose the file is CIE_STATUS_FILE.DAT, then ##*/ will display CIE_STATUS_FILE

+3  A: 

This also works in Bash and is described here:

${string##substring}

Deletes longest match of $substring from front of $string.

The * is a wildcard which means match anything. Your example removes the path from the file, not the extension.

$ bazfile='/foo/bar/baz.txt'
$ echo ${bazfile##*/}
baz.txt

To remove the extension you want to use %:

${string%substring}

Deletes shortest match of $substring from back of $string.

$ echo ${bazfile%.*}
/foo/bar/baz
Mark Byers