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

220
Vistas
execute printf command shell script

I am a beginner in writing shell script (probably my 1st shell script). I have a shell script that I like to run. The command is a simple grep command based on the parameter passed to it. I managed to get the correct grep command using the script below.

FILE='testurls'
MERCHANT_ID='8'
printf "grep '^%s' %s\n" "$MERCHANT_ID" "$FILE"

./hello.sh 
grep '^8' testurls

How would I execute the command instead of printing it.

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

0

printf is not necessary

FILE='testurls'
MERCHANT_ID='8'
grep "^$MERCHANT_ID" "$FILE"
over 4 years ago · Santiago Trujillo Denunciar

0

You can use shell backticks quotes. This will store the output of executable commands.

Syntax are :-

1) Legacy Bourne shell backticks ``:

var=`grep "^$MERCHANT_ID" "$FILE"` 
printf "%s\n" "$var"

2) $() syntax:

var=$(grep "^$MERCHANT_ID" "$FILE")
printf "%s\n" "$var"
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