[英]Cannot use alias while executing a command via SSH
我在.bashrc中注釋掉了這一行:
# [ -z "$PS1" ] && return
現在別名被讀取,但我仍然無法執行...:/
我們可以詢問服務器是否已定義別名:
$ ssh server "cd /tmp && alias backup_tb"
alias backup_tb='pg_dump -U david tb > tb.sql'
但它沒有擴大:
$ ssh server "cd /tmp && backup_tb"
bash: backup_tb: command not found
有任何想法嗎?
引自bash
的手冊頁: 當shell不是交互式時,別名不會被展開,除非使用shopt設置了expand_aliases shell選項...
因此,最簡單的方法是將以/home/<user>/.bashrc
放在/home/<user>/.bashrc
文件的頂部:
# comment out the original line
# [ -z "$PS1" ] && return
if [ -z "$PS1" ]; then
shopt -s expand_aliases
# alias ls='ls --color=always'
# return
fi
保存並退出。 現在您可以成功運行ssh user@host "your_alias"
。
# WARNING!!!! Just effective in openssh-server.!!!!!!!
# cd your loacl user .ssh path
# if you want to make all user has the same alias you should go to
#'/etc/ssh' touch a file 'sshrc'
# what is 'sshrc'? he has the same function as 'rc.local',just a shell
# script when you first login.
# The following is a configuration of the current user .
cd ~/.ssh
touch sshrc
chmod +x sshrc
#edit sshrc and type
alias ll="ls -lah --color"
#Apply changes
source sshrc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.