0

I'm pretty unfamiliar with bash syntax and I'm running into a problem of how to use strings from a previous operation as inputs into subsequent ones. Here's what I have now:

#!/bin/bash

searchTerm=$1

results=$(npm search $searchTerm --json | jq '.[].name')

for term in $results
do
  info=$(npm info $term)

  echo "####" $info
done

The command that executes looks like the following and fails:

npm info "\"exampleTerm\""

How do I use $term in the for loop in combination with npm info?

2
  • Answer: info=$(eval npm info "$term") Commented May 27, 2017 at 22:08
  • What does the output of npm search $searchTerm --json | jq '.[].name' look like? Commented May 27, 2017 at 22:11

2 Answers 2

1

A (long) one-liner will do it…

npm search react-redux --json | jq '.[].name' | xargs -I pkg sh -c 'echo "#### $(npm info $1)"' - pkg
Sign up to request clarification or add additional context in comments.

Comments

0

Answer is to use eval like the following:

#!/bin/bash

searchTerm=$1

results=$(npm search $searchTerm --json | jq '.[].name')

for term in $results
do
  info=$(eval npm info "$term")

  echo "####" $info
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.