bash - How to save the result of grep to variable x? -


#!/bin/bash  in *.pdf;      echo $i     x= pdfinfo "$i" | grep "title" # nothing stored in variable x     echo $x      if [ ! -z $x ];         echo $x # print null         cp $i "$x"     fi done 

nothing stored in variable x — why not , how do it.

add parentheses or backquotes:

x=$(pdfinfo "$i" | grep "title") 

or

x=`pdfinfo "$i" | grep "title"` 

note latter solution should avoided now, historical way of doing , replaced $(...). $(...) solution more readable in particular in case of nested substitutions.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -