1

I want to take a local file and zip it at some other temp location. Following is my code which is giving error

path="/home/tft/Downloads/ie.js"
temp="/home/tft/Downloads/Temp"
name=$(basename "$path")
echo "$path"
echo "$name"
echo "$temp"
echo "$temp/$name.zip" #Its output is also weird!
zip -r -j "$temp/$name.zip" $path 

Getting below output:

 /bin/bash test.sh

/home/tft/Downloads/ie.js
ie.js
/home/tft/Downloads/Temp
.zipjstft/Downloads/Temp 
        zip warning: name not matched: /home/tft/Downloads/ie.js

)zip . -i /home/tft/Downloads/ie.js -r -j /home/tft/Downloads/Temp

1 Answer 1

2

Your script is in DOS format. Convert it first to UNIX format:

sed -i 's|\r||' yourscript.sh

Or use dos2unix:

dos2unix yourscript.sh

The error messages you see is caused by having an extra character (carriage return \r) at the end of your values. This happens when your file's format is not UNIX but DOS since DOS' line endings is \r\n where UNIX only has \n.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh great. this solved it. Never knew about it. Thanks

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.