我想检查是否所有的笔记本电脑都有良好的软件版本之前,安装和配置一个工具。
我需要提取并比较以下版本:
- 节点
- npm
- java
- Git
- Visual Studio程式码
- Python
我的代码:
#!/bin/bash
# Couleur pour mieux voir les reponses
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
# Version des sofwares
version_Nodejs=`node --version | cut -c 2-6`
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}i
}'
}
eval $(parse_yaml config.yml "config_")
function verification_version() {
if [ $2 -eq $3 ]
echo $2
echo $3
then
echo -e "The version installed on your machine ${MACHINE} for $1 is $GREEN $version_Nodejs that is correct. $NOCOLOR"
else
echo - e "The version installed for $1 is $RED not correct $NOCOLOR. Create a Service Now request to ask to have $1 $2 minumum on your machine ${MACHINE} "
# echo - e "$RED For Zowe CLI Call the support $NOCOLOR"
exit 1
fi
}
# Verification des versions des Softwares
verification_version $config_NODEJS $version_Nodejs $config_VNODE
在我的config.yml文件上
---
NODEJS: NodeJs
VNODE: 16.20
当我运行它的时候
$ ./Init_VDIcopy.sh
./Init_VDIcopy.sh: line 34: [: 16.15: integer expression expected
16.15
16.20
The version installed on your machine for NodeJs is 16.15 that is correct.
1条答案
按热度按时间tuwxkamq1#
我改变了我的函数的代码如下,这是更好的
我们可以结案非常感谢你的帮助