为什么我的别名不适用于 "sh -c"?

Why my alias does not work with "sh -c"?

我不明白为什么,在我的服务器上

php --version 

给我:

PHP 5.6.17 

sh -c 'php --version'

给我:

PHP 4.4.9 

我只想在 php 5.6 中执行命令,而不是在 php 4.4 中使用 "sh -c" 命令执行命令。

换句话说,为什么我的 php 别名不能与 "sh -c" 一起使用?

如何让它与"sh -c"一起工作?

我的.bash_profile:

# .bash_profile

# Get the aliases and functions
if [ -r ${HOME}/.bashrc ] ; then
  source ${HOME}/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
BASH_ENV=$HOME/.bashrc
USERNAME=""

export USERNAME BASH_ENV PATH

我的.bashrc :

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

alias php='/usr/local/php5.6/bin/php'

比较 bash --versionsh --version 的输出。

您的 sh 实际上不是 bash,因此 .bashrc 在启动时未被获取,因此别名 php 未在新的 shell.