LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   syntax error unexpected token near "then" (https://www.linuxquestions.org/questions/linux-newbie-8/syntax-error-unexpected-token-near-then-650650/)

pclimmex 06-20-2008 10:22 PM

syntax error unexpected token near "then"
 
I am working with Knoppix 4
I am working to replace a file on a crashed computer. I can locate the file and a second file of the same name on the hd1 (atisgkaf.sys WinXP)

I can not just replace it with the "good" file because of permissions. I am using the Knoppix Hacks (O'Reilly)
It states that writing to NTFS files can be done.

I was going to test my abilities with a few different command line attempts before trying to replace the file.

I entered ... from the book... p231
$ find /mnt/hda1/ -name *.cab -exec sh -c "if cabextract -l \"{}\" 2>/dev/null | grep atisgkaf.sys; then echo \"*{}\"; fi; " \;

return is an syntax error unexpected token near "then". If I remove"then" it changes to a different

Mr. C. 06-20-2008 10:51 PM

Some tips:
  1. You need to place quotes around your *.cab so that the shell doesn't try to glob it before find gets a chance to see the *.
  2. With a simple if a then b, you can use a simpler construct: a && b.
  3. Using single quotes around your command passed to sh is easier, and find still looks for {} inside (since the shell has already removed the quotes, find sees {} just fine).

So, ultimately you have:

Code:

find /mnt/hda1 -name '*.cab' -exec sh -c 'cabextract -l "{}" 2>/dev/null | grep atisgkaf.sys && echo "*{}"' \;


All times are GMT -5. The time now is 02:18 PM.