# Linux aliases in shell...

**URL:** <https://forum.ansible.com/t/linux-aliases-in-shell/22875>\
**Category:** Ansible Project\
**Created:** [October 25, 2016, 1:52am UTC](https://forum.ansible.com/t/linux-aliases-in-shell/22875 "2016-10-25T01:52:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sonny\_Chee](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sonny\_Chee](https://forum.ansible.com/u/Sonny_Chee)\
**Post date:** [October 25, 2016, 1:52am UTC](https://forum.ansible.com/t/linux-aliases-in-shell/22875/1 "2016-10-25T01:52:15Z")

</div>

Hey Guys,

Is there a way to make aliases available in a shell? I tried sourcing a file with aliases before invoking my alias with no luck… ie:

shell: . ~/.bash\_aliases && my\_command args

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [October 25, 2016, 8:29am UTC](https://forum.ansible.com/t/linux-aliases-in-shell/22875/2 "2016-10-25T08:29:17Z")

</div>

> Is there a way to make aliases available in a shell? I tried sourcing a file with aliases before invoking my alias with no luck

[https://linux.die.net/man/1/bash](https://linux.die.net/man/1/bash) :

> Aliases are not expanded when the shell is not interactive, unless the expand\_aliases shell option is set using shopt

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Sonny\_Chee](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sonny\_Chee](https://forum.ansible.com/u/Sonny_Chee)\
**Post date:** [October 26, 2016, 11:55pm UTC](https://forum.ansible.com/t/linux-aliases-in-shell/22875/3 "2016-10-26T23:55:29Z")

</div>

Thanks Paul, that makes sense.

Is it possible to set this behavior within Ansible? I tried the following without any luck…

shell: rs -z blah\_blah  
args:  
creates: “{{ current\_flags }}/{{ item }}\_{{ ansible\_date\_time.date }}”  
executable: /bin/bash +O expand\_aliases

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [October 27, 2016, 2:44pm UTC](https://forum.ansible.com/t/linux-aliases-in-shell/22875/4 "2016-10-27T14:44:00Z")

</div>

> Is it possible to set this behavior within Ansible? I tried the following without any luck…

I would recommend that you don’t use aliases in non-interactive shells. If the script grows, maybe use the script-module instead [https://docs.ansible.com/ansible/script\_module.html](https://docs.ansible.com/ansible/script_module.html) . Another option is to use shell functions instead of aliases.

Cheers,  
Paul
