Volver a las herramientas

Analizador de scripts Bash

Pega un script de shell y encuentra los errores que solo aparecen en el servidor: variables sin comillas, scripts #!/bin/sh que usan sintaxis exclusiva de bash, rm -rf $VAR, un fi sin cerrar. Cada aviso se explica en lenguaje claro, con la línea y columna exactas.

Entrada

Tu script

No se sube nada: la comprobación se ejecuta en esta pestaña. Pega el archivo completo, incluido el shebang, para que funcione la detección de dialecto.

1 línea(s) comprobadas.

Resultado

Resumen

Comprobador basado en patrones para los errores comunes y de mayor impacto en bash — no es una implementación completa de ShellCheck y no detectará todo. Pásalo por ShellCheck para un análisis completo
Shebang
No se detectó ningún shebang
Errores
0
Avisos
1
Notas
0

Pega un script arriba, o carga el ejemplo, para comprobarlo.

Se aplicaron 1 corrección(es): 1 × shebang added

Hallazgos

Qué va a fallar, y por qué

Solo errores de corrección, no preferencias de estilo o portabilidad.

GravedadLínea:ColReglaMensajeCorrección
warning1:1WX100

No shebang line

Without a #! line, what runs the script depends entirely on how it is invoked. "./script.sh" hands it to whatever the kernel falls back to, cron runs it under /bin/sh, and your interactive test under bash works fine — so it passes locally and fails as a cron job.

Add as the very first line: #!/usr/bin/env bash

Referencia

Chuleta de errores habituales

Los errores que busca este analizador, y cómo es la corrección. Son los que sobreviven a las pruebas locales y fallan en producción.

Always quote expansions

cp $src $dst
cp "$src" "$dst"

Unquoted, the value is split on whitespace and then glob-expanded. One path with a space becomes two arguments.

"$@", never $@

mycmd $@
mycmd "$@"

"$@" is the only form that passes every argument through exactly as received, including empty ones.

[[ ]] is bash, [ ] is POSIX

#!/bin/sh … [[ -f $f ]]
#!/bin/sh … [ -f "$f" ]

On Debian and Ubuntu /bin/sh is dash. [[ does not exist there — "[[: not found" and the test is false.

Strings with =, numbers with -eq

[ "$n" = 10 ]
[ "$n" -eq 10 ]

= compares text, so "010" ≠ "10". -eq compares integers and errors loudly on non-numeric input.

cd can fail

cd /srv/app rm -rf ./cache
cd /srv/app || exit 1 rm -rf ./cache

If cd fails the script continues in the previous directory — and the next relative command hits the wrong tree.

Guard rm against an empty variable

rm -rf $DIR/
rm -rf "${DIR:?DIR is not set}"/

An unset $DIR makes this "rm -rf /". ${VAR:?msg} aborts instead of expanding to nothing.

Never read and write one file

sort f.txt > f.txt
sort f.txt > f.tmp && mv f.tmp f.txt

The redirect truncates the file before sort opens it, so you are left with an empty file.

Assignments take no spaces

NAME = value
NAME=value

With spaces the shell runs NAME as a command. The variable is never set and every later $NAME is empty.

Glob the directory, do not parse ls

for f in $(ls *.log)
for f in *.log

ls output is one string that gets split on whitespace, so filenames with spaces split into pieces.

read needs -r

while read line
while IFS= read -r line

Without -r, backslashes are eaten. Without IFS=, leading and trailing whitespace is stripped.

$? is only the last command

mycmd echo done [ $? -ne 0 ]
if ! mycmd; then …

The echo resets $?. Test the command directly rather than inspecting the status later.

Fail fast, fail loudly

#!/bin/bash
#!/bin/bash set -euo pipefail

-e stops on the first failure, -u catches typoed variable names, pipefail makes a broken pipeline fail.

¿Tienes tu propio servidor de juegos?

Servidores de juegos Wespner con protección DDoS, discos NVMe y activación en pocos minutos.

Ver hosting