bash脚本选项卡

时间:2012-09-03 12:07:45

标签: bash scripting escaping

我是Bash脚本的新手。

以下是脚本中包含的命令:

arecacli64 disk info通常会:

  # Ch# ModelName                       Capacity  Usage

===============================================================================
  1  1  ST3750330NS                      750.2GB  Raid Set # 00   
  2  2  ST3750330NS                      750.2GB  Raid Set # 00   
  3  3  ST3750330NS                      750.2GB  Raid Set # 00   
  4  4  ST3750330NS                      750.2GB  Raid Set # 00   
  5  5  ST3750330NS                      750.2GB  Raid Set # 00   
  6  6  ST3750330NS                      750.2GB  Raid Set # 00   
  7  7  ST3750330NS                      750.2GB  Raid Set # 00   
  8  8  ST3750330NS                      750.2GB  Raid Set # 00   
  9  9  ST3750330NS                      750.2GB  Raid Set # 00   
 10 10  ST3750330NS                      750.2GB  Raid Set # 00   
 11 11  ST3750330NS                      750.2GB  Raid Set # 00   
 12 12  ST3750330NS                      750.2GB  Raid Set # 00   
 13 13  ST3750330NS                      750.2GB  Raid Set # 00   
 14 14  ST3750330NS                      750.2GB  Raid Set # 00   
 15 15  ST3750330NS                      750.2GB  Raid Set # 00   
 16 16  ST3750330NS                      750.2GB  Raid Set # 00   
 17 17  ST3750330NS                      750.2GB  Raid Set # 00   
 18 18  ST3750330NS                      750.2GB  Raid Set # 00   
 19 19  ST3750330NS                      750.2GB  Raid Set # 00   
 20 20  ST3750330NS                      750.2GB  HotSpare[Global]
 21 21  ST3750330NS                      750.2GB  Raid Set # 00   
 22 22  ST3750330NS                      750.2GB  Raid Set # 00   
 23 23  ST3750640NS                      750.2GB  Raid Set # 00   
 24 24  ST3750330NS                      750.2GB  Raid Set # 00   
===============================================================================

我的简单脚本是:

F=`dmidecode |grep  "Product Name:"|cut -d ":" -f2|head -1`

if [ $F == "X7DB8" ]
then
echo
echo
echo -e "$VERT" HOSTNAME : `hostname`"$NORMAL"
echo -e "$BLEU" TYPE :"$NORMAL" `dmidecode -s system-manufacturer`
echo -e "$BLEU" MODEL :"$NORMAL" `dmidecode -t system |grep "Product Name:"|cut -d ":" -f2`


echo "-------------------->"
echo

echo -e  `/usr/local/bb/ext/Raid/arecacli64 disk info`

fi

但是结果显示(raid ctrl的部分)没有显示命令arecalcli64 disk info

的任何标签
 HOSTNAME : xxxx@www.com
 TYPE : Supermicro
 MODEL : X7DB8
-------------------->


  # Ch# ModelName Capacity Usage =============================================================================== ST3750330NS 750.2GB Raid Set # 00 2 2 
ST3750330NS 750.2GB Raid Set # 00 3 3 
ST3750330NS 750.2GB Raid Set # 00 4 4 
ST3750330NS 750.2GB Raid Set # 00 5 5 
ST3750330NS 750.2GB Raid Set # 00 6 6 
ST3750330NS 750.2GB Raid Set # 00 7 7 
ST3750330NS 750.2GB Raid Set # 00 8 8 
ST3750330NS 750.2GB Raid Set # 00 9 9 
ST3750330NS 750.2GB Raid Set # 00 10 10 
ST3750330NS 750.2GB Raid Set # 00 11 11 
ST3750330NS 750.2GB Raid Set # 00 12 12 
ST3750330NS 750.2GB Raid Set # 00 13 13 
ST3750330NS 750.2GB Raid Set # 00 14 14 
ST3750330NS 750.2GB Raid Set # 00 15 15 
ST3750330NS 750.2GB Raid Set # 00 16 16 
ST3750330NS 750.2GB Raid Set # 00 17 17 
ST3750330NS 750.2GB Raid Set # 00 18 18 
ST3750330NS 750.2GB Raid Set # 00 19 19 
ST3750330NS 750.2GB Raid Set # 00 20 20 
ST3750330NS 750.2GB HotSpare[Global] 21 21 
ST3750330NS 750.2GB Raid Set # 00 22 22 
ST3750330NS 750.2GB Raid Set # 00 23 23 
ST3750640NS 750.2GB Raid Set # 00 24 24 
ST3750330NS 750.2GB Raid Set # 00 =============================================================================== GuiErrMsg: Success.

我尝试使用\t \sed等。

2 个答案:

答案 0 :(得分:4)

而不是

echo -e  `/usr/local/bb/ext/Raid/arecacli64 disk info`

只需使用

/usr/local/bb/ext/Raid/arecacli64 disk info

答案 1 :(得分:0)

如果引用命令替换,您将获得正确的输出。

echo  "`/usr/local/bb/ext/Raid/arecacli64 disk info`"

不需要-e标志,因为您没有指定任何\t个字符;该 标签嵌入在arecacli64的输出中,并通过引用保留 它的输出。

但正如kkeller指出的那样,首先不需要使用命令替换。