本文介绍了##*/在 UNIX Shell 脚本中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能详细说明 ##*/在 UNIX Shell 脚本中是如何工作的.我已经看到它在 Korn Shell 中使用.专门用于去除文件扩展名.

例如func_write_app_log "o 正在删除状态文件 ${CIE_STATUS_FILE##*/}"

这里假设文件是​​CIE_STATUS_FILE.DAT,那么##*/会显示CIE_STATUS_FILE

解决方案

这也适用于 Bash 并被描述 这里:

${string##substring}

从 $string 前面删除 $substring 的最长匹配项.

* 是一个通配符,表示匹配任何内容.您的示例从文件中删除路径,而不是扩展名.

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

删除你想使用的扩展%:

${string%substring}

从 $string 后面删除 $substring 的最短匹配项.

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

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

解决方案

This also works in Bash and is described here:

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 %:

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

这篇关于##*/在 UNIX Shell 脚本中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:47