bash - 别名的有效形式是什么?
问题描述
我正在尝试在 bash 中实现 alias 命令的基本行为,我只想知道名称的有效形式。
解决方案
我看了一下 Bash 源代码,@chepner 的评论是正确的。任何未被 shell 解释的字符已经是有效的。所以像$
,/
和之类的东西=
是不允许的。
来自general.c,https: //ftp.gnu.org/gnu/bash/bash-5.0.tar.gz
/* Return 1 if STRING comprises a valid alias name. The shell accepts
essentially all characters except those which must be quoted to the
parser (which disqualifies them from alias expansion anyway) and `/'. */
int
legal_alias_name (string, flags)
const char *string;
int flags;
{
register const char *s;
for (s = string; *s; s++)
if (shellbreak (*s) || shellxquote (*s) || shellexp (*s) || (*s == '/'))
return 0;
return 1;
}
推荐阅读
- android - 按钮缩放动画制作背景剪辑
- thymeleaf - Thymeleaf:结合#strings函数
- openstack - 关于用neutron的dhcp分配ip地址
- php - 在 laravel 中使用用户提供的模型名称动态制作模型
- php - 在php上解码base64图像得到空白图像
- c# - 如何将不同的 ViewModel 传递给通用方法?
- symfony - Symfony 4.1 功能测试中的环境变量/隔离环境变量
- javascript - 在反应中使用 dispatchEvent 时不会触发复选框更改事件
- angular - 如果名称重复,堆叠器水平条形图不显示正确的数据
- javascript - 从类 javascript 中调用函数