This question already has an answer here:

$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

I was wondering how I can pass the aliases from the shell to a script? Thanks.

$ cat myscript 

$ ./myscript 

marked as duplicate by jasonwryan, Sparhawk, Patrick, Kusalananda bash Jun 24 '18 at 8:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Aliases are intentionally cleared before starting a script, as aliases could cause scripts to missbehave.

In theory, you could define aliases inside a script, but if such a script is run via

. scriptname

it is not granted that these new aliases are used inside the script, since dot scripts are parsed completely before they are run and to make an alias effective the parser need to know it and in order to let the parser know the alias, you first need to run the alias shell builtin command.

So just don't use aliases in scripts. They are something to make typing easier and this does not apply to scripts that are written once but run many times.

Not the answer you're looking for? Browse other questions tagged or ask your own question.