Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
"if [ -z $variable ]" in a shell script is not recognising my variable

When I run the following script it keeps defaulting to the else statement and I'm not sure why. I have even included an echo $workflow which showed me the name that I was expecting to see but it still keeps defaulting to the else statement.

I've tried including an export namecheck=$workflow to see if that was the issue but it still gave the same end result

#!/bin/sh

read -p "Enter the workflow name: " workflowName

workflowName=${workflowName}

curl --request GET --url https://website.com > workflowjson.txt

workflow=$(jq -r .metadata.name workflowjson.txt)

echo $workflow

if [ -z "$workflow" ] then
    echo "Workflow is Valid" 
else
    echo "Workflow is not valid" 
fi
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

man test shows

-z STRING the length of STRING is zero

The code outputs Workflow is Valid when the workflow is empty.

Switch the then and else parts, or negate the condition (use -n instead of -z).

over 4 years ago · Santiago Trujillo Denunciar

0

try taking the quotes out around workflow and put then in a separate line

if [ -z $workflow ]
then
  echo "Workflow is Valid" 
else
  echo "Workflow is not valid"
fi
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda