Works in terminal but not in script

1.9k Views Asked by At
pip install sphinx
sphinx-quickstart -q -p DSPackageDocs -a Me -v 1 --ext-autodoc
perl -i -e $'s/#sys.path.insert(0, os.path.abspath(\'.\'))/sys.path.insert(0, os.path.abspath(\'.\/DSPackage\'))/g' conf.py

The 3rd line looks into a file and replaces some text. Specifically, I replace

sys.path.insert(0, os.path.abspath('.')) 

with

sys.path.insert(0, os.path.abspath('./DSPackage'))

This line works perfectly fine in the terminal in the shell script I get the error:

Syntax error: ")" unexpected

1

There are 1 best solutions below

0
On BEST ANSWER

I'm getting the error if I execute the command in dash. dash doesn't seem to support the $'...' quotes.

It works OK in bash, and emits different errors in zsh and ksh:

Unknown regexp modifier "/D" at -e line 1, at end of line
Unknown regexp modifier "/S" at -e line 1, at end of line
Unknown regexp modifier "/P" at -e line 1, at end of line
Unknown regexp modifier "/k" at -e line 1, at end of line
Can't find string terminator "'" anywhere before EOF at -e line 1.

Make sure to specify the correct shell on the first line of the script

#! /bin/bash

and to call the script correctly:

/path/to/the/script.sh

or

cd /path/to/the
./script.sh