Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

219
Views
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 answers
Answer question

0

printf is not necessary

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

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!