![意外标记“(”附近出现语法错误](https://linux22.com/image/84495/%E6%84%8F%E5%A4%96%E6%A0%87%E8%AE%B0%E2%80%9C(%E2%80%9D%E9%99%84%E8%BF%91%E5%87%BA%E7%8E%B0%E8%AF%AD%E6%B3%95%E9%94%99%E8%AF%AF.png)
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
。