Richard Rublev Richard Rublev - 4 months ago 9
Bash Question

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?

I got the code from

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

Answer

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. In your question, this line is missing and thus the alias never gets called.