zdd8vw
Last Updated: February 25, 2016
·
286
· victorbrca
409302 10151131950910230 214813917 n 2

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'
Say Thanks
Respond
Filed Under