I commented out this line in .bashrc:
# [ -z "$PS1" ] && return
and now the alias gets read, but I still cannot execute it... :/
We can ask the server if the alias has been defined:
$ ssh server "cd /tmp && alias backup_tb"
alias backup_tb='pg_dump -U david tb > tb.sql'
But it is not expanded:
$ ssh server "cd /tmp && backup_tb"
bash: backup_tb: command not found
Any ideas?
Quoted from the man page of bash
: Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt ...
So the simplest way IMO is to put the following lines at the top of your /home/<user>/.bashrc
file:
# comment out the original line
# [ -z "$PS1" ] && return
if [ -z "$PS1" ]; then
shopt -s expand_aliases
# alias ls='ls --color=always'
# return
fi
Save and exit. Now you can run ssh user@host "your_alias"
successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With