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

361
Vistas
Running commands in a loop without spawning a new subshell each time

I have a bash script that reads in lots of dates in epoch time, and determines the (local) hour of the day at which they occurred. Relevant snippet:

while read ts
do
  hour="$(date -d@$((${ts} / 1000)) +%H)"
  ((hourly_counts["${hour}"]+=1))
done < "${jqfile}"

It's rather slow, because it spawns a new subshell for each invocation of date. Is there a sensible way round this? It looks as though date doesn't support multiple queries.

All I can think of is to spawn a new shell, and pipe date commands to it and get the results back, so that they all execute in the same shell. But I'm not clear on how to do this, and it seems a little over-engineered.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Use printf:

printf -v hour '%(%H)T' "$(( ts / 1000 ))"

Type help printf to know more about the command.

Also check strftime(3). Behavior may depend on the value of TZ and LC_TIME.

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