2

Can I use hexdump in a shell script?

When I use it I keep getting an error .

syntax error near unexpected token '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

I am not able to figure out why the hexdump code is giving me an error . Please help .

  • Did you try to execute your script with `bash -x`? – antiguru May 20 '16 at 04:23
  • Yes it gives me the same error. – Abhishake Yadav May 20 '16 at 04:31
  • You're missing the `do`, aren't you? That is: `for file in /argus/raid2/"$line"/*.ffid` and `hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1` and `done` should be `for file in /argus/raid2/"$line"/*.ffid; do hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > list1; done` (semicolons added for use in a comment; not necessary in the script if `do` and `done` are each on a line of their own). – Jonathan Leffler May 20 '16 at 04:33
  • I want to use the hexdump command on each file in the directory as it appears. – Abhishake Yadav May 20 '16 at 04:35
  • You need to learn [how to debug a shell script](https://stackoverflow.com/questions/951336/how-to-debug-a-bash-script/951352#951352) — succinctly `sh -x yourscript.sh`. Also, you need to learn how to create an MCVE ([MCVE]). Showing the exact error message would have shown the line number. You wouldn't need many lines after that to be able to maintain the error while eliminating many lines of code. You might even have spotted the problem yourself. – Jonathan Leffler May 20 '16 at 04:36
  • 1
    http://www.shellcheck.net is great and would have shown you many of your mistakes. For example, you can't assign with spaces around the `=` sign, and the parameter to the left of the equal sign must not have `$` prepended. – Benjamin W. May 20 '16 at 04:38
  • Thanks Benjamin....I was looking for something like this – Abhishake Yadav May 20 '16 at 04:44

1 Answers1

4

You are missing the do in your for loop:

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

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

done 
Joe
  • 25,000
  • 3
  • 22
  • 44