bash脚本没有读取bashrc中的别名 [英] bash script not reading alias in bashrc

查看:26
本文介绍了bash脚本没有读取bashrc中的别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .bashrc 文件中创建了一个别名:

I have created an alias in the .bashrc file:

alias java='java -Xmx1200m'

当我直接从我的 shell 运行 java 命令时,这个别名有效.

This alias works when I run a java command from my shell directly.

但是,当 java 命令位于 bash 脚本 (script.sh) 中时,该别名不会被激活.如何确保 .bashrc 文件中的别名在 bash 脚本中被接受??

However, when the java command is inside a bash script (script.sh), this alias does not get activated. How do I ensure that the aliases in .bashrc file are accepted in a bash script ??

推荐答案

别名不会在非交互式 shell 中展开.

Alias are not expanded in non-interactive shells.

创建别名的唯一方法是使用包含别名的脚本来获取目标脚本.

The only way to make an alias is to source the target script with the one which contains the alias.

$ source .bashrc
$ . custom_script.sh

这篇关于bash脚本没有读取bashrc中的别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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