为什么一个别名工作&QUOT内变量扩展;如预期"只有这些情况吗? [英] Why does variable expansion within an alias work "as intended" in only one of these cases?

查看:142
本文介绍了为什么一个别名工作&QUOT内变量扩展;如预期"只有这些情况吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是部分由这个。

alias foo='ls -1 $1'
foo /etc

显示/ etc下,每行一个项目的内容。

displays the contents of /etc, one item per line.

ls -1 /etc | tail

显示/ etc中的最后十个项目。

displays the last ten items in /etc.

alias foo='ls -1 $1 | tail'
foo /etc

显示:尾:错误读取`/等':是一个目录

displays: tail: error reading `/etc': Is a directory

推荐答案

我已经找到别名变量扩展为片状,而不是推荐:

<一href=\"http://www.gnu.org/software/bash/manual/bashref.html#Aliases\">http://www.gnu.org/software/bash/manual/bashref.html#Aliases

I have found variable expansion in aliases to be flaky, and not recommended:
http://www.gnu.org/software/bash/manual/bashref.html#Aliases

使用的函数:函数foo(){LS -1 $ 1; }

这篇关于为什么一个别名工作&QUOT内变量扩展;如预期&QUOT;只有这些情况吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆