--- name: find_free_port kind: function lang: bash domain: shell version: "1.0.0" purity: impure signature: "find_free_port([start_port: int], [end_port: int]) -> int" description: "Busca el primer puerto TCP libre en un rango dado usando ss y lsof. Retorna el numero de puerto a stdout." tags: [network, port, shell, utility] uses_functions: [] uses_types: [] returns: [] returns_optional: false error_type: "error_go_core" imports: [] params: - name: start_port desc: "puerto inicial del rango (default: 8888)" - name: end_port desc: "puerto final del rango (default: 8899)" output: "nĂºmero de puerto TCP libre" tested: false tests: [] test_file_path: "" file_path: "bash/functions/shell/find_free_port.sh" --- ## Ejemplo ```bash source find_free_port.sh port=$(find_free_port 8888 8899) echo "Puerto libre: $port" # Con defaults (8888-8899) port=$(find_free_port) ``` ## Notas Usa `ss -tln` como primer intento y `lsof` como fallback. Ambos deben confirmar que el puerto no esta en uso. Si ningun puerto esta libre en el rango, sale con exit code 1.