You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux CentOS服务器Red5媒体服务器安装报错求助

Fix: /etc/init.d/red5: line 22: if: command not found on CentOS

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 after if or before [[)
  • ❌ Wrong: if[ -f "$RED5_HOME/red5.sh" ] (no space after if)
  • ✅ 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:46:20