当用login shell方式使用zsh的时候,比如ssh登陆,会出现
/etc/profile.d/xdg-data-dirs-opt-apps.sh:10: command not found: shopt
/etc/profile.d/xdg-data-dirs-opt-apps.sh:18: no matches found: /opt/apps/*/entries
由于/etc/zsh/zprofile里是直接source /etc/profle.d下的文件
# Begin /etc/profile
# Written for Beyond Linux From Scratch
# by James Robertson <jameswrobertson@earthlink.net>
# modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
# System wide environment variables and startup programs.
# System wide aliases and functions should go in /etc/bashrc. Personal
# environment variables and startup programs should go into
# ~/.bash_profile. Personal aliases and functions should go into
# ~/.bashrc.
# Source profile scripts
for script in /etc/profile.d/* ; do
case "$script" in
*.bash)
[ "$BASH" ] && . "$script" ;;
*.sh)
. "$script" ;;
esac
done
# Now to clean up
unset pth script
# End /etc/profile
而zsh用的是setopt,而不是shopt
所以我的解决办法是这样更改xdg-data-dirs-opt-apps.sh
# shopt -s nullglob
if [[ $(readlink /proc/$$/exe) == "/usr/bin/bash" ]]; then
shopt -s nullglob
elif [[ $(readlink /proc/$$/exe) == "/usr/bin/zsh" ]]; then
setopt NULL_GLOB
fi
判断当前的shell是zsh还是bash,来执行不同的命令
就结果而言好像是好了,但由于我对shell编程不是很熟,所以想请教一下这样改是可行的吗?