LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Can't use aliases in non-interactive ssh command (https://www.linuxquestions.org/questions/linux-software-2/cant-use-aliases-in-non-interactive-ssh-command-695817/)

openSauce 01-08-2009 05:26 AM

Can't use aliases in non-interactive ssh command
 
Hi,

when I use ssh to open an interactive shell on my machine, I can use all the aliases I normally would on that machine. But when I use ssh to run a single non-interactive command, the aliases don't work. How can I fix this?

Example:
Code:

# sshhome is an alias to ssh to my home machine
3$ sshhome
Last login: Thu Jan  8 11:01:44 2009 from *****
~$ alias testal
alias testal='echo aliases are A-OK'
~$ testal
aliases are A-OK
~$ exit
logout
Connection to ***** closed.
3$ sshhome "alias testal; testal"
alias testal='echo aliases are A-OK'
bash: testal: command not found
3$

Note that using the alias command does correctly display the alias.

colucix 01-08-2009 06:11 AM

Quote:

Originally Posted by openSauce (Post 3400956)
Note that using the alias command does correctly display the alias.

Yes. The alias is assigned but it is not expanded (executed) when the shell is not interactive.

You have two options:
1) convert the aliases in functions
2) add the following line to your .bashrc on the remote machine
Code:

shopt -s expand_aliases

openSauce 01-08-2009 06:52 AM

Option 2 isn't working for me unfortunately. Also doesn't work if I do the shopt as part of the ssh command: ssh "shopt -s expand_aliases; [command]". Option 1 works fine, although feels kludgy. Thanks


All times are GMT -5. The time now is 04:13 PM.