防止bash别名在shell启动时评估语句 [英] Prevent bash alias from evaluating statement at shell start

查看:64
本文介绍了防止bash别名在shell启动时评估语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有以下别名。

alias pwd_alias='echo `pwd`'

此别名不是动态的。 Shell启动后,它将立即评估 pwd 。无论如何,是否要延迟对报价中表达式的求值,直到别名运行时为止?

This alias is not "dynamic". It evaluates pwd as soon as the shell starts. Is there anyway to delay the evaluation of the expression in the ticks until the alias's runtime?

推荐答案

您真正想要的是一个函数

What you really want is a function, instead of an alias.

pwd_alias() {
   echo "$PWD"
}

别名只不过是替换文本。任何复杂性都需要一个函数。

Aliases do nothing more than replace text. Anything with complexity calls for a function.

这篇关于防止bash别名在shell启动时评估语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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