##*/ use in UNIX Shell Scripting

2019-04-11 08:01发布

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

标签: unix shell
1条回答
仙女界的扛把子
2楼-- · 2019-04-11 08:21

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
查看更多
登录 后发表回答