-4
$ 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 
#!/bin/bash
alias

$ ./myscript 
$
Tim
  • 101,790

1 Answers1

0

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.

schily
  • 19,173