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'
Written by Victor Mendonca
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Related Tags
#bash
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#