JAVA(JDK)를 설치한 후 시스템을 다시 시작하거나 일반 사용자로 전환할 때마다 다음 메시지가 나타납니다.
bash: ${AUTO_CLASSPATH_DIR}: invalid variable name
bash: ${AUTO_CLASSPATH_DIR}: invalid variable name
이것은 구성 스크립트입니다.
cat > /etc/profile.d/openjdk.sh << "EOF"
# Begin /etc/profile.d/openjdk.sh
# Set JAVA_HOME directory
JAVA_HOME=/opt/jdk
# Adjust PATH
pathappend $JAVA_HOME/bin
# Add to MANPATH
pathappend $JAVA_HOME/man MANPATH
# Auto Java CLASSPATH: Copy jar files to, or create symlinks in, the
# /usr/share/java directory. Note that having gcj jars with OpenJDK 8
# may lead to errors.
AUTO_CLASSPATH_DIR=/usr/share/java
pathprepend . CLASSPATH
for dir in `find ${AUTO_CLASSPATH_DIR} -type d 2>/dev/null`; do
pathappend $dir CLASSPATH
done
for jar in `find ${AUTO_CLASSPATH_DIR} -name "*.jar" 2>/dev/null`; do
pathappend $jar CLASSPATH
done
export JAVA_HOME
unset AUTO_CLASSPATH_DIR dir jar
# End /etc/profile.d/openjdk.sh
EOF
이것은의 출력입니다bash -xv /etc/profile.d/openjdk.sh
pathappend () { pathremove $1 $2;
local PATHVARIABLE=${2:-PATH};
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}
pathprepend () { pathremove $1 $2;
local PATHVARIABLE=${2:-PATH};
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
pathremove () { local IFS=':';
local NEWPATH;
local DIR;
local PATHVARIABLE=${2:-PATH};
for DIR in ${!PATHVARIABLE};
do
if [ "$DIR" != "$1" ]; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR;
fi;
done;
export $PATHVARIABLE="$NEWPATH"
}
# Begin /etc/profile.d/openjdk.sh
# Set JAVA_HOME directory
JAVA_HOME=/opt/jdk
+ JAVA_HOME=/opt/jdk
# Adjust PATH
pathappend $JAVA_HOME/bin
+ pathappend /opt/jdk/bin
+ pathremove /opt/jdk/bin
+ local IFS=:
+ local NEWPATH
+ local DIR
+ local PATHVARIABLE=PATH
+ for DIR in ${!PATHVARIABLE}
+ '[' /bin '!=' /opt/jdk/bin ']'
+ NEWPATH=/bin
+ for DIR in ${!PATHVARIABLE}
+ '[' /usr/bin '!=' /opt/jdk/bin ']'
+ NEWPATH=/bin:/usr/bin
+ for DIR in ${!PATHVARIABLE}
+ '[' /opt/jdk/bin '!=' /opt/jdk/bin ']'
+ export PATH=/bin:/usr/bin
+ PATH=/bin:/usr/bin
+ local PATHVARIABLE=PATH
+ export PATH=/bin:/usr/bin:/opt/jdk/bin
+ PATH=/bin:/usr/bin:/opt/jdk/bin
# Add to MANPATH
pathappend $JAVA_HOME/man MANPATH
+ pathappend /opt/jdk/man MANPATH
+ pathremove /opt/jdk/man MANPATH
+ local IFS=:
+ local NEWPATH
+ local DIR
+ local PATHVARIABLE=MANPATH
+ for DIR in ${!PATHVARIABLE}
+ '[' /usr/share/man '!=' /opt/jdk/man ']'
+ NEWPATH=/usr/share/man
+ for DIR in ${!PATHVARIABLE}
+ '[' opt/jdk/man '!=' /opt/jdk/man ']'
+ export MANPATH=/usr/share/man
+ MANPATH=/usr/share/man
+ local PATHVARIABLE=MANPATH
+ export MANPATH=/usr/share/man:/opt/jdk/man
+ MANPATH=/usr/share/man:/opt/jdk/man
# Auto Java CLASSPATH: Copy jar files to, or create symlinks in, the
# /usr/share/java directory. Note that having gcj jars with OpenJDK 8
# may lead to errors.
AUTO_CLASSPATH_DIR=/usr/share/java
+ AUTO_CLASSPATH_DIR=/usr/share/java
pathprepend . CLASSPATH
+ pathprepend . CLASSPATH
+ pathremove . CLASSPATH
+ local IFS=:
+ local NEWPATH
+ local DIR
+ local PATHVARIABLE=CLASSPATH
+ for DIR in ${!PATHVARIABLE}
+ '[' . '!=' . ']'
+ export CLASSPATH=
+ CLASSPATH=
+ local PATHVARIABLE=CLASSPATH
+ export CLASSPATH=.
+ CLASSPATH=.
for dir in `find ${AUTO_CLASSPATH_DIR} -type d 2>/dev/null`; do
pathappend $dir CLASSPATH
done
+ for dir in `find ${AUTO_CLASSPATH_DIR} -type d 2>/dev/null`
+ pathappend find '${AUTO_CLASSPATH_DIR}' -type d '2>/dev/null` CLASSPATH
+ pathremove find '${AUTO_CLASSPATH_DIR}'
+ local IFS=:
+ local NEWPATH
+ local DIR
+ local 'PATHVARIABLE=${AUTO_CLASSPATH_DIR}'
environment: line 4: ${AUTO_CLASSPATH_DIR}: invalid variable name
for jar in `find ${AUTO_CLASSPATH_DIR} -name "*.jar" 2>/dev/null`; do
pathappend $jar CLASSPATH
done
+ for jar in `find ${AUTO_CLASSPATH_DIR} -name "*.jar" 2>/dev/null`
+ pathappend find '${AUTO_CLASSPATH_DIR}' -name '"*.jar"' '2>/dev/null` CLASSPATH
+ pathremove find '${AUTO_CLASSPATH_DIR}'
+ local IFS=:
+ local NEWPATH
+ local DIR
+ local 'PATHVARIABLE=${AUTO_CLASSPATH_DIR}'
environment: line 4: ${AUTO_CLASSPATH_DIR}: invalid variable name
export JAVA_HOME
+ export JAVA_HOME
unset AUTO_CLASSPATH_DIR dir jar
+ unset AUTO_CLASSPATH_DIR dir jar
# End /etc/profile.d/openjdk.sh
출력 파일에서 AUTO_CLASSPATH_DIR에 대해 잘못된 변수 이름도 기록되었습니다.
bash 5.0(BLFS 8.4 환경)을 사용하고 있습니다.
답변1
문제는 역따옴표와 작은따옴표를 구분할 수 없다는 것입니다. (이 작업을 오래된 노트북에서 수행하고 있기 때문에 모든 항목을 입력해야 합니다.) 그 후 다시 스크립트를 작성했는데 잘 작동했습니다.