bash 两个横线有什么特殊含义吗

this="${BASH_SOURCE-$0}" bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P) script="$(basename -- "$this")" this="$bin/$script" 上面是hadoop启动时的一段代码,这段逻辑也比较...
this="${BASH_SOURCE-$0}"
bin=$(cd -P -- "$(dirname -- "$this")" && pwd -P)
script="$(basename -- "$this")"
this="$bin/$script"
上面是hadoop启动时的一段代码,这段逻辑也比较简单(this最终为该脚本的绝对物理位置),就是不明白,-Pdirname后面的--的作用是什么?

bash的man page是这么写的:

A -- signals the end of options and disables further option
processing. Any arguments after the -- are treated as filenames and
arguments. An argument of - is equivalent to --.

两个横线代表选项的结束,两个横线后面的部分都会被认为是参数了,而不再是前面的命令的选项了。


说明 

BASH_SOURCE-$0 默认为 -bash dirname -bash 是会报错的,因为 dirname 没有 -bash这个选项。前面加-- 会把 “-bash" 当成 dirname 的参数,而不是选项,这样就不会报错了

  • 发表于 2020-12-25 19:57
  • 阅读 ( 44 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
shitian
shitian

662 篇文章

作家榜 »

  1. shitian 662 文章
  2. 石天 437 文章
  3. 每天惠23 33 文章
  4. 小A 29 文章