简体   繁体   English

Bash脚本和别名

[英]Bash script and alias

I am trying to run this script 我正在尝试运行此脚本

#!/bin/bash
# alias.sh

shopt -s expand_aliases
# Must set this option, else script will not expand aliases.


# First, some fun.
alias Jesse_James='echo "\"Alias Jesse James\" was a 1959 comedy starring Bob Hope."'

echo;
echo

As output I got two empty lines only.Why? 作为输出,我只有两条空行,为什么?

Do I need to export alias.sh into .bashrc?If yes,why? 我是否需要将alias.sh导出到.bashrc中?如果是,为什么?

I got the code from 我从那里得到了代码

http://tldp.org/LDP/abs/html/aliases.html http://tldp.org/LDP/abs/html/aliases.html

The complete example is: 完整的示例是:

#!/bin/bash
# alias.sh

shopt -s expand_aliases
# Must set this option, else script will not expand aliases.


# First, some fun.
alias Jesse_James='echo "\"Alias Jesse James\" was a 1959 comedy starring Bob Hope."'
Jesse_James

In this case, the alias Jesse_James gets called on the last line. 在这种情况下,别名Jesse_James在最后一行被调​​用。 In your question, this line is missing and thus the alias never gets called. 在您的问题中,此行丢失,因此永远不会调用别名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM