0

I'm a newbie to Unix shell scripts, and can't understand why this doesn't work as the individual commands do on on the command line. Apologies if its obvious.

I am trying to build a script with some Unix commands, and call it using sh script.sh in Putty. Here is a sample:

echo Carrying out compression
gzip -c file_1.csv > file_1.csv.gz
gzip -c file_2.csv > file_2.csv.gz
gzip -c file_3.csv > file_3.csv.gz

Rather than producing the specified named output, I am getting very weird named files eg. FTY4WG~7. That is except for the last one which is named correctly.

If I put a space after each line, it works but I get an error message: : No such file or directory

Actually I'm trying to do a whole bunch of stuff (stitching together CSVs as well as compressing them), but if I can crack this simple command I'll probably be able to work it all out.

Thanks for your help!

Ben

1
  • 4
    Check that your script does not use DOS line endings. Commented Mar 6, 2013 at 17:54

1 Answer 1

1

make sure you have this line at the top of the script

#!/bin/bash

Now execute this command

dos2unix <yourfilename>

Now do this

chmod u+x <urfilename>

May be this will do.

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

Comments

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.