0

I am trying to turn the following into an executable bash script

#!/bin/bash

cd ~/mlpractical
source activate mlp
jupyter notebook

after creating a .rtf file with the above, i then execute from the correct directory

chmod u+x filename

but everytime i then try and open the file i get an output telling me on line 1) the command is not found, on line 2) there is a syntax error etc.

How do I make the script executable (double-clickable) and resolve this error?

Juju Head
  • 11
  • 3

2 Answers2

2

I'm not sure about making the script double-clickable (that depends on your OS, and you didn't mention what OS you're using). But it sounds like the script file is in RTF format, and that will certainly cause trouble. Shell scripts must be in absolutely plain Unix-style text files.

  • They can't have any formatting info, as in RTF, DOC, DOCX, etc files. At best, the shell will try to interpret the formatting info as shell commands, and get lots of errors.
  • They must have Unix-style line endings. If you use a text editor that saves in DOS/Windows format, you'll have trouble.
  • They must use a plain enough character encoding that the shell can get away with treating it as plain ASCII. That means no UTF-16. UTF-8 is ok, but don't use fancy characters like curly quotes (“ ” and ‘ ’) -- stick to plain ASCII quotes (" " and ' '). And no byte order marks!
Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
0

Thanks Gordon, You are right the errors all made clear that text formatting strings were what was being passed to the shell, instead of just the plain text strings i intended.

I am using a MacOS environment and was creating files in text edit which had no .txt option only .rtf

I solved the issue by,

1) using the command line itself to echo text to a file without any extension eg.

echo 'text' > filename

2) i then couldn't figure out the newline syntax so had to keep appending text eg.

echo 'more text' >> filename

3) i then did the following, from the relevant directory, to make it executable,

chmod u+x filename
Juju Head
  • 11
  • 3