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
Post a Comment