Em bash
, você pode usar a variável $LINENO
para essa finalidade:
echo Installing NGINX. Line: $LINENO
$LINENO
contém o número da linha atual, consulte man bash
:
LINENO
Each time this parameter is referenced, the shell substitutes a decimal number representing the current sequential line number (starting with 1) within a script or function. When not in a script or func‐ tion, the value substituted is not guaranteed to be meaningful. If LINENO is unset, it loses its spe‐ cial properties, even if it is subsequently reset.
Exemplo
#!/bin/bash
echo $LINENO; echo $LINENO
echo $LINENO
Quando executado, este script imprime:
2
2
4