apt install:正则表达式和 var=regex 之间的区别

apt install:正则表达式和 var=regex 之间的区别

我目前在 apt install 的脚本中遇到问题,不明白为什么。

有什么区别:

# works fine
apt install gstreamer1.0-plugins-{bad,base,good,ugly}

var="gstreamer1.0-plugins-{bad,base,good,ugly}"
apt install $var

[...]
E: Unable to locate package gstreamer1.0-plugins-{bad,base,good,ugly}
E: Couldn't find any package by glob 'gstreamer1.0-plugins-{bad,base,good,ugly}'
E: Regex compilation error - Invalid content of \{\}
E: Couldn't find any package by regex 'gstreamer1.0-plugins-{bad,base,good,ugly}'
E: Unable to locate package gstreamer1.0-{omx,alsa}
E: Couldn't find any package by glob 'gstreamer1.0-{omx,alsa}'
E: Regex compilation error - Invalid content of \{\}
E: Couldn't find any package by regex 'gstreamer1.0-{omx,alsa}'

亲切的问候

答案1

你有大括号扩展而不是正则表达式。大括号扩展在引号内或分配/扩展变量时不起作用。

你的第一个命令正在做什么:

apt install gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly

你的第二个命令正在做什么:

apt install "gstreamer1.0-plugins-{bad,base,good,ugly}"

相关内容