Проблема в том, что команда работает, а вот если ее сделать алиасом, уже нет.
root@12345:~# GottenCode=$(mysql -e "SELECT code FROM dictionaries.shop" | egrep -ao [0-9]{10} | echo `hostname` | egrep -ao [0-9]{11} | tail -n 1) | mysql -e "SELECT address FROM dictionaries.shop WHERE code LIKE '%$GottenCode%'"
------------------------------------------------------------
address
Кукуево
alias adr='GottenCode=$(mysql -e "SELECT code FROM dictionaries.shop" | egrep -ao [0-9]{10} | echo `hostname` | egrep -ao [0-9]{11} | tail -n 1) | mysql -e "SELECT address FROM dictionaries.shop WHERE code LIKE '%$GottenCode%'"'
root@12345:~# adr
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%12345%' at line 1