- 主题:unar -- "$FILENAME" 这两个减号什么意思?
我以前写的脚本,
unar -- "$FILENAME"
我现在搞不懂这两个减号什么意思了
类似的有
cp -a -- "$FILENAME" "$LOCATION" ;;
--
FROM 125.86.90.*
查这些工具的manpage看不到这样的用法,但是这些工具的参数解析可能是用getopt(1)做的,getopt(1)里面有说明。
The parameters getopt is called with can be divided into two parts: op‐
tions which modify the way getopt will do the parsing (the options and
the optstring in the SYNOPSIS), and the parameters which are to be
parsed (parameters in the SYNOPSIS). The second part will start at the
first non-option parameter that is not an option argument, or after the
first occurrence of '--'. If no '-o' or '--options' option is found in
the first part, the first parameter of the second part is used as the
short options string.
【 在 gnwd (gnwd) 的大作中提到: 】
: 我以前写的脚本,
: unar -- "$FILENAME"
: 我现在搞不懂这两个减号什么意思了
: ...................
--
FROM 103.90.178.*
一个方面,可能是安全原因,--表示此后没有更多option了,即便有人(可能恶意)在后面变量里塞一个-x之类的,也不被视为命令的option. 防命令行注入攻击。
我试过用shellcheck检查过我的一个脚本,其中一个建议就是某处要加--,具体编号SC多少我忘了。
【 在 gnwd 的大作中提到: 】
: 我以前写的脚本,
: unar -- "$FILENAME"
: 我现在搞不懂这两个减号什么意思了
: ...................
--来自微水木3.5.10
--
FROM 113.115.60.*
这个观点我还真没想过。以前看一些博文说过通配符展开,文件名有空格之类的问题,把--和这些联系在一起还没想过。
【 在 Dazzy (大懒虫,脱焦省却磨皮) 的大作中提到: 】
: 一个方面,可能是安全原因,--表示此后没有更多option了,即便有人(可能恶意)在后面变量里塞一个-x之类的,也不被视为命令的option. 防命令行注入攻击。
: 我试过用shellcheck检查过我的一个脚本,其中一个建议就是某处要加--,具体编号SC多少我忘了。
: --来自微水木3.5.10
: ...................
--
FROM 103.90.178.*
shellcheck对一些危险的写法会提出警告的,比如rm -rf "$somewhere"/
这种如果$somewhere为空,会变成系统自杀的写法,SC就会剔出来。强烈建议修正,加强对参数检查。
【 在 ArchLinux 的大作中提到: 】
: 这个观点我还真没想过。以前看一些博文说过通配符展开,文件名有空格之类的问题,把--和这些联系在一起还没想过。
:
: 【 在 Dazzy (大懒虫,脱焦省却磨皮) 的大作中提到: 】
: ...................
--来自微水木3.5.10
--
FROM 113.115.60.*
牛
【 在 ArchLinux 的大作中提到: 】
:
: 查这些工具的manpage看不到这样的用法,但是这些工具的参数解析可能是用getopt(1)做的,getopt(1)里面有说明。
:
: The parameters getopt is called with can be divided into two parts: op‐
: tions which modify the way getopt will do the parsing (the options and
#发自zSMTH@Redmi K20 Pro Premium Edition
--
FROM 119.85.29.*
https://unix.stackexchange.com/questions/11376/what-does-double-dash-meanMore precisely, a double dash (--) is used in most bash built-in commands and many other commands to signify the end of command options, after which only positional arguments are accepted.
Example use: lets say you want to grep a file for the string -v - normally -v will be considered the option to reverse the matching meaning (only show lines that do not match), but with -- you can grep for string -v like this:
grep -- -v file
【 在 gnwd (gnwd) 的大作中提到: 】
: 我以前写的脚本,
: unar -- "$FILENAME"
: 我现在搞不懂这两个减号什么意思了
: ...................
--
FROM 116.232.51.*
搞错了,应该是getopt(3). getopt(1)是util-linux里的一个程序,getopt(3)才是POSIX函数。关于"--"的描述getopt(3)是这么说的。
By default, getopt() permutes the contents of argv as it scans, so that
eventually all the nonoptions are at the end. Two other scanning modes
are also implemented. If the first character of optstring is '+' or
the environment variable POSIXLY_CORRECT is set, then option processing
stops as soon as a nonoption argument is encountered. If the first
character of optstring is '-', then each nonoption argv-element is han‐
dled as if it were the argument of an option with character code 1.
(This is used by programs that were written to expect options and other
argv-elements in any order and that care about the ordering of the
two.) The special argument "--" forces an end of option-scanning re‐
gardless of the scanning mode.
【 在 gnwd (gnwd) 的大作中提到: 】
: 牛
: #发自zSMTH@Redmi K20 Pro Premium Edition
--
FROM 103.90.178.*
这个例子很好-v作为一个字符串
谢谢
【 在 RuralHunter 的大作中提到: 】
:
:
https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean :
: More precisely, a double dash (--) is used in most bash built-in commands and many other commands to signify the end of command options, after which only positional arguments are accepted.
:
#发自zSMTH@Redmi K20 Pro Premium Edition
--
FROM 119.85.29.*
可以用于对付 文件名首字母是横线的情况
比如文件名是 -abc.txt
因为横线原因会被认成一个选项
【 在 gnwd 的大作中提到: 】
: 我以前写的脚本,
: unar -- "$FILENAME"
: 我现在搞不懂这两个减号什么意思了
: ...................
--
FROM 119.248.226.*