Linux CentOS服务器Red5媒体服务器安装报错求助
This error almost always stems from a syntax quirk or shell compatibility issue in your Red5 init script. Let’s work through the most common fixes step by step:
1. Fix the script’s shebang line
The first line of your /etc/init.d/red5 script tells the system which shell to use to run it. If it’s set to #!/bin/sh but uses Bash-specific syntax (like [[ ]] conditionals), you’ll hit this error—CentOS’s default sh doesn’t support all Bash features.
How to fix:
Open the script with an editor:
vi /etc/init.d/red5
Change the first line from:
#!/bin/sh
To:
#!/bin/bash
Save and exit, then try running the script again.
2. Check the if statement syntax on line 22
Most often, this error comes from missing spaces around conditional brackets or incorrect formatting. Here are common mistakes and fixes:
- ❌ Wrong:
if[[ -n "$RED5_HOME" ]](no space afterifor before[[) - ❌ Wrong:
if[ -f "$RED5_HOME/red5.sh" ](no space afterif) - ✅ Correct:
if [[ -n "$RED5_HOME" ]] - ✅ Correct:
if [ -f "$RED5_HOME/red5.sh" ]
Also make sure the if statement is followed by then (either on the same line with a semicolon or a new line):
# Valid format 1 if [ -d "$RED5_HOME" ]; then echo "Red5 directory exists" fi # Valid format 2 if [ -d "$RED5_HOME" ] then echo "Red5 directory exists" fi
To see the exact line and its context, run this command:
cat -n /etc/init.d/red5 | sed -n 18,26p
Adjust the line range if needed to get a clearer view of the problematic code.
3. Fix Windows-style line endings (CRLF)
If you transferred the script from a Windows machine, it might have CRLF line endings instead of Unix-style LF. This can break shell script parsing entirely.
How to fix:
Install dos2unix to convert the line endings:
yum install -y dos2unix dos2unix /etc/init.d/red5
Then try running the script again.
Quick test to confirm the issue
If you want to bypass the shebang temporarily to rule out shell compatibility, run the script directly with Bash:
bash /etc/init.d/red5 start
If this works, the shebang line fix above will resolve the problem permanently.
内容的提问来源于stack exchange,提问作者Math02

