Last Updated: February 25, 2016
·
2.059K
· victorbrca

Call aliases from your shell script

Let's say you have defined an alias in your script and you try calling it from the same script:

$ cat aliases.sh 
#!/bin/bash

alias ll='ls -lFh'
type ll

By default Bash will fail with the following error:

$ ./aliases.sh
./aliases.sh: line 5: type: ll: not found

Solution:

Use 'shopt -s expand_aliases' from your script to expand aliases:

$ cat aliases.sh 
#!/bin/bash

shopt -s expand_aliases
alias ll='ls -lFh'
type ll

And here's the working result:

$ ./aliases.sh 
ll is aliased to `ls -lFh'