1
#!/bin/bash

cp ./Source/* ./Working/ 2> /dev/null
echo "Done"


for filename in *.zip;do unzip “$filename”;
 done

In the above script, I am trying to copy all the files from source to working and unzip the files in working folder but I am geting igetting an error unexpected end of file

2
  • It’s probably unzip that reports this error. Commented May 20, 2013 at 16:57
  • As an aside, you can use -v with copy to output more results while copying. rsync is also another command with nice output. Commented May 20, 2013 at 17:09

2 Answers 2

3

It looks like you have different kinds of double quotes in "$filename", make sure both are ASCII double quotes (decimal 34, hex 22). Try analyzing your script with

 od -c scriptname
Sign up to request clarification or add additional context in comments.

Comments

0

You have up to two problems here. First you quotes are not standard. You probably copy pasted from MS Word or something that automatically converts quotes.

The second problem you may have is that your filenames may have spaces in it. This can cause all sorts of problems in scripts if you do not expect it. There are a few workarounds but the easiest is probably to change the IFS:

OLDIFS=$IFS
IFS="$(echo -e '\t\n')" # get rid of the space character in the IFS
... do stuff ...
IFS=$OLDIFS

5 Comments

No need for messing with IFS if "$filename" is doublequoted.
Quoting cannot solve all problems with spaces depending on usage. In the above example you should be fine, but consider the following. touch file "test file" "another file"; echo *file* > input; for i in $(cat input); do echo $i; done
That's just buggy programming :-) Use for i in *file*; do echo "$i"; done and all is well again.
My example was contrived but from a real issue. Image if the input file was generated by some other process and it is to be used in a script. In that case that IFS would have to be changed. In a simple case such as what the OP put it is not needed.
I'm not sure I agree. Handling spaces in input is easy even without manipulating IFS: while read -r line; do echo "$line"; done < input. Proper quoting is all you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.