1

请分享更多想法以从 bash 命令获取软件版本并稍后将其用作变量。

 su --version
su (GNU coreutils) 5.97
Copyright etc.

并为其结果创建变量。就像我在下面尝试过的一样。

su --version >/tmp/temp.txt

if [ -f /tmp/temp.txt ]; then
    elv=`cat /tmp/temp.txt | gawk 'BEGIN {FS="(GNU coreutils)"} {print $2}' | gawk 'BEGIN {FS="."} {print $1}'`
    #Version String. Just a shortcut to be used later
    els=el$elv
else
    echo "Unable to determine version. I can't continue"
    exit 1
fi

if [ `rpm -qa | egrep -c -i "^mysql-"` -gt 0 ]; then
cat << EOF

It appears that the distro-supplied version of MySQL is at least partially installed,
or a prior installation attempt failed.

Please remove these packages, as well as their dependencies (often postfix), and then
retry this script:

$(rpm -qa | egrep -i "^mysql-")

EOF
exit 1
fi
4

0 回答 0