Bash是否有类似于|| =的内容?Bash or-equals || = like Ruby
也就是说,有没有更好的方式来做到以下几点:
if [ -z $PWD ]; then PWD=`pwd`; fi
我这么问是因为我得到这个错误:
$ echo ${`pwd`/$HOME/'~'}
-bash: ${`pwd`/$HOME/'~'}: bad substitution
所以,我的计划是要做到:
if [ -z $PWD ]; then PWD=`pwd`; fi
echo ${PWD/$HOME/'~'}
我真正的问题是:“有没有更好的方法来做到以下几点?”
# ~/.bash_profile
# Set prompt to RVM gemset, abbr. of current directory & (git branch).
PROMPT_COMMAND='CUR_DIR=`pwd|sed -e "s!$HOME!~!"|sed -E "s!([^/])[^/]+/!\1/!g"`'
PS1='$(~/.rvm/bin/rvm-prompt g) [$CUR_DIR$(__git_ps1)]\$ '
不不同的(或更好的)但更短的:'[-z $ PWD] && PWD = \'pwd \'' – pje