Bash 在查找匹配的`';

Bash 在查找匹配的`';,bash,shell,eof,Bash,Shell,Eof,我有一个大学的BASH项目,我有两个我不理解的错误 下面是我的脚本BASH: #!/bin/bash proc_name=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f1 | uniq`; proc_freq=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f2 | uniq`; proc_core=`cat /proc

我有一个大学的BASH项目,我有两个我不理解的错误

下面是我的脚本BASH:

#!/bin/bash

proc_name=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f1 | uniq`;
proc_freq=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f2 | uniq`;
proc_core=`cat /proc/cpuinfo | grep 'cpu cores' | cut -d':' -f2 | uniq`;
proc_hyperthreading=`cat /proc/cpuinfo | grep 'siblings' | cut -d':' -f2 | uniq`;
proc_architecture=`lscpu | grep '64-bit' | cut -d',' -f2 | cut -d'-' -f1`;
proc_cache_L1=`lscpu | grep 'Cache L1i' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_cache_L2=`lscpu | grep 'Cache L2' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_cache_L3=`lscpu | grep 'Cache L3' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_virtualisation=`lscpu | grep 'Virtualisation' | cut -d':' -f2 |sed "s/\ \ */\ /g"`;
proc_load_average=`w | head -1 | cut -d" " -f12 | cut -d"," -f1-2` | tr ',' '.'`

ip_infos_addr_ipv4=`/sbin/ifconfig eth0 | awk '/inet adr:/{print $2}' | awk -F ':' '{print $2}'`;
ip_infos_addr_ipv6=`/sbin/ifconfig eth0 | awk '/adr inet6:/{print $3}'`;
ip_publique_addr=`dig +short myip.opendns.com @resolver1.opendns.com`;
carte_reseau=`lspci |grep Ethernet | cut -d":" -f3`;


echo -e "$proc_name\n$proc_freq\n$proc_core\n$proc_hyperthreading\n$proc_architecture\n$proc_cache_L1\n$proc_cache_L2\n$proc_cache_L3\n$proc_virtualisation\n$proc_load_average\n$ip_infos_addr_ipv4\n$ip_infos_addr_ipv6\n$ip_publique_addr\n$carte_reseau" > Collecteur/collecteur_cpu_reseau.txt;
以下是我的两个错误:

./collecteur_cpu_reseau: line 17: unexpected EOF while looking for matching ``'
./collecteur_cpu_reseau: line 21: syntax error: unexpected end of file
提前谢谢你的帮助

proc_load_average=`w | head -1 | cut -d" " -f12 | cut -d"," -f1-2` | tr ',' '.'`
…需要

# remove the extra backtick
proc_load_average=`w | head -1 | cut -d" " -f12 | cut -d"," -f1-2 | tr ',' '.'`
……或者更好

# use parens, not backticks
proc_load_average=$(w | head -1 | cut -d" " -f12 | cut -d"," -f1-2 | tr ',' '.')
# read the content straight from procfs without the big silly pipeline
read -r loadavg_1min loadavg_5min loadavg_10min _ </proc/loadavg
echo "1-minute load average: $loadavg_1min"
……或者更好

# use parens, not backticks
proc_load_average=$(w | head -1 | cut -d" " -f12 | cut -d"," -f1-2 | tr ',' '.')
# read the content straight from procfs without the big silly pipeline
read -r loadavg_1min loadavg_5min loadavg_10min _ </proc/loadavg
echo "1-minute load average: $loadavg_1min"

…这不是更容易吗?通过替换
lscpu
。此外,…运行
lscpu
如此多次,而不是只运行一次,重复使用结果是非常低效的,顺便说一句;我建议重新考虑你的方法。我认为你在
proc\u load\u average=
行中有太多的反勾号(````)。所以突出显示有助于隔离它!。。。使用反勾号是不好的做法;命令替换的现代语法是
$(…)