rhel_major=$(grep -Eoh [0-9]+\.[0-9]+ /etc/{issue,*release} | head -1 | awk -F'.' '{ print $$1 }')
rhel_minor=$(grep -Eoh [0-9]+\.[0-9]+ /etc/{issue,*release} | head -1 | awk -F'.' '{ print $$2 }')
rhel_release_code=$(echo $$(($(rhel_major) << 8 | $(rhel_minor))))
对于 rhel_release_code 我收到语法错误
rhel_release_code=$(echo $$(("$(rhel_major)" << 8 | $(rhel_minor))))
-bash: command substitution: line 1: syntax error near unexpected token `('
-bash: command substitution: line 1: `echo $$(("$(rhel_major)" << 8 | $(rhel_minor)))'
知道为什么它会抛出这个错误吗?
答案1
bash
抛出错误,因为它不是有效的 shell 代码。 (这也不是有效的awk
代码。)
尝试这个
rhel_major=$(grep -Eoh '[0-9]+\.[0-9]+' /etc/{issue,*release} | awk -F'.' '{ print $1; exit }')
rhel_minor=$(grep -Eoh '[0-9]+\.[0-9]+' /etc/{issue,*release} | awk -F'.' '{ print $2; exit }')
rhel_release_code=$((rhel_major << 8 | rhel_minor))
如果您实际上不需要$rhel_major
和$rhel_minor
值,您可以$rhel_release
使用 直接一步计算awk
。