【问题标题】:Can I use hexdump in a shell script?我可以在 shell 脚本中使用 hexdump 吗?
【发布时间】:2016-05-20 04:19:19
【问题描述】:

我可以在 shell 脚本中使用 hexdump 吗?

当我使用它时,我不断收到错误消息。

意外标记“hexdump”附近的语法错误

#!/bin/bash
#bash-hexdump
# Quick script to check delay of the shotpoints 

echo " please enter the complete line name as mentioned in the RAID2 "

read $line

cd /argus/raid2/"$line"


echo
echo " Entering the directory "
echo
for file in /argus/raid2/"$line"/*.ffid

hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1 

done 

for filename in 'cat list1'
do 
sed -n 6p | awk '{print $1}' = $wd

cat list.txt | sed -n 1p | cut -c13-14 = $hh

cat list.txt | sed -n 1p | cut -c15-16 = $mm


cat list.txt | sed -n 2p | cut -c1-2 = $ss


done 

while [ true ]
do

$FFID=`ls -1rt $1 | grep -i ffid | tail -1`
echo " FFID value is : $FFID"
while [ $FFID = `ls -1rt $1 | grep -i ffid | tail -1` ]
do
hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list 
done
for filename in 'cat list'
 do 


             cat list.txt | sed -n 1p | cut -c13-14 = $hh1

             cat list.txt | sed -n 1p | cut -c15-16 = $mm1

             cat list.txt | sed -n 2p | cut -c1-2 = $ss1



done

$time1 = "$hh"":""$mm"":""$ss" ;

$time2 = "$hh1"":""$mm1"":""$ss1" ;

$former_seconds = $(date --date= "$time1" +%s);

$later_seconds = $(date --date= "$time2" +%s);

$time_delay = ( "$later_seconds" - "$former_seconds" ) 


$wb_time = ( "$wd" * 1.33 )

if 

(("$wb_time" + "$time_delay")) < 12.0

then 

 echo "please slow down"

 fi


 if [ -e  EOL.ffid ]
    then
            echo "EOL.ffid detected, exiting script"
            exit
    fi


  done

我无法弄清楚为什么 hexdump 代码给了我一个错误。请帮忙。

【问题讨论】:

  • 您是否尝试使用bash -x 执行您的脚本?
  • 是的,它给了我同样的错误。
  • 你错过了do,不是吗?即:for file in /argus/raid2/"$line"/*.ffidhexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' &gt; list1done 应该是 for file in /argus/raid2/"$line"/*.ffid; do hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' &gt; list1; done(添加分号以用于注释;如果 dodone 各自位于一行,则在脚本中不需要) .
  • 我想对目录中出现的每个文件使用 hexdump 命令。
  • shellcheck.net 很棒,会向您展示您的许多错误。例如,您不能在 = 符号周围分配空格,并且等号左侧的参数不能在前面加上 $

标签: linux shell sh


【解决方案1】:

您的 for 循环中缺少 do

for file in /argus/raid2/"$line"/*.ffid
do

hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1 

done 

【讨论】:

  • 非常感谢您的帮助,乔。
  • 我想在目录中的每个文件上循环这个十六进制转储命令,然后对每个文件的输出进行计算。
猜你喜欢
  • 1970-01-01
  • 2015-03-07
  • 1970-01-01
  • 2013-05-31
  • 1970-01-01
  • 2011-06-24
  • 2011-11-26
  • 1970-01-01
  • 2016-09-22
相关资源
最近更新 更多