V
V
Vladislav2020-07-14 11:30:32
linux
Vladislav, 2020-07-14 11:30:32

How to fix bash script error?

I am writing a script that will automatically create site folders, turn on configs and restart the server.
Already at the first stages there were errors, despite the fact that the actions themselves are performed correctly.
But apparently bash still does something besides my functions.
Here is the first lines of the script, there are the same errors. After each line this error:

echo "Write your domain without http and www:";
read sitedomain;
sudo mkdir -p /var/www/$sitedomain/public_html;
echo Hello world >/var/www/$sitedomain/public_html/index.html;

And the error itself (createsite: line 1: $'\r': command not found):
IgnuTBMuCVc.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xotkot, 2020-07-14
@cr1gger

perform before running the script
dos2unix СКРИПТ
will remove all problems that may arise when working with the script from under Windows
p.s.
The semicolon(;) is redundant unless you are executing multiple commands in a row on the same line.
It is better to take the path to the file / directory in which there is a variable in double ("") quotes, otherwise if a value with a space suddenly gets into the variable, then there will be an incident
and it is better to reduce duplication:

echo "Write your domain without http and www:"
read sitedomain
DIR="/var/www/$sitedomain"
sudo mkdir -p "$DIR/public_html"
echo "Hello world" > "$DIR/public_html/index.html"

U
unseriously, 2020-07-14
@unseriously

Well, just in case, it's better to specify the absolute path to the utilities, that is: /bin/echo, /bin/mkdir, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question