0

I'm trying to make a Bash shell script but it is not working. Here is the contents of the script:

#!/bin/bash pwd 

I would expect this to print out the current directory. Instaed, it prints this:

: not found: build.sh: #!/bin/bash : not found: build.sh: : not found: build.sh: pwd 

Why is it doing that? I can't find any articles of other people having this problem.

I did chmod 777 on the script, and am running it like so:

sh build.sh 
3
  • 2
    looks like some file format issue. Was the file created in linux or imported from windows? What gives the command 'file build.sh' ? Commented Jan 22, 2018 at 11:39
  • @tonioc I think you might be right! It's being saved on Windows and uploaded. What would the right encoding be? Commented Jan 22, 2018 at 17:19
  • 3
    @Abr The file probably has DOS/Windows-style line endings. See "Are shell scripts sensitive to encoding and line endings?" on stackoverflow. BTW, you should almost never use chmod 777 (do you really want all users to be able to edit the script?), and run scripts with ./build.sh rather than explicitly using sh. Commented Jan 22, 2018 at 17:45

1 Answer 1

1

The file probably has DOS/Windows-style line endings.

See "Are shell scripts sensitive to encoding and line endings?" on stackoverflow.

BTW, you should almost never use chmod 777 (do you really want all users to be able to edit the script?), and run scripts with ./build.sh rather than explicitly using sh.

– Gordon Davisson Jan 22 at 17:45

1
  • As this is more or less the accepted answer, I believe it should be filed as one. Not taking credit, though. Commented Jan 31, 2018 at 20:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.