bash Linux Shell 脚本 dirname 和 ? 方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20391068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux Shell script what dirname and ? means?
提问by Elvin
Can any body tell me what this command means?
任何人都可以告诉我这个命令是什么意思吗?
selfDir=$(cd "$(dirname "dirname /usr/local/bin/add.sh
/usr/local/bin
")"; pwd) ?
I know
我知道
$0
= running script namepwd
= current working dircd
= to change dir
$0
= 运行脚本名称pwd
= 当前工作目录cd
= 改变目录
What I need is what is dirname? and what ?means at end to make this line completely understandable.
我需要的是dirname是什么?什么?意味着最后使这条线完全可以理解。
采纳答案by Vinayak Pahalwan
The dirname command removes the trailing / component from the NAME and prints the remaining portion. If the NAME does not contain / component then it prints '.' (means current directory)
dirname 命令从 NAME 中删除尾随 / 组件并打印剩余部分。如果 NAME 不包含 / 组件,那么它会打印 '.' (表示当前目录)
Dirname Command Example:
目录名命令示例:
Remove the file name from absolute path.
从绝对路径中删除文件名。
Let say my directory path is /usr/local/bin/add.sh. Now i want to remove /add.sh and display only /usr/local/bin, then we can use the dirname command.
假设我的目录路径是/usr/local/bin/add.sh。现在我想删除 /add.sh 并只显示 /usr/local/bin,然后我们可以使用 dirname 命令。
dirname NAME
dirname OPTION
NAME
姓名
dirname
- strip non-directory suffix from file name
dirname
- 从文件名中去除非目录后缀
SYNOPSIS
概要
##代码##DESCRIPTION
描述
Print NAME with its trailing /component removed; if NAME contains no /'s, output ‘.' (meaning the current directory).
打印 NAME 并删除其尾随 /component;如果 NAME 不包含 /,则输出 '.' (意思是当前目录)。
Edit:Also, Some characters have special functions in linux commands ?
<-- Matches one character
编辑:此外,某些字符在 linux 命令中具有特殊功能?
<-- 匹配一个字符