Reputation: 5
#!/bin/bash
for i in *.pdf; do
echo $i
x= pdfinfo "$i" | grep "Title" # nothing is stored in variable x
echo $x
if [ ! -z $x ]; then
echo $x # print null
cp $i "$x"
fi
done
Nothing is stored in variable x
— but why not and how do I do it.
Upvotes: 0
Views: 149
Reputation: 18821
Add parentheses or backquotes:
x=$(pdfinfo "$i" | grep "Title")
or
x=`pdfinfo "$i" | grep "Title"`
Note that the latter solution should be avoided now, it is the historical way of doing it and is replaced by $(...)
. The $(...)
solution is more readable in particular in case of nested substitutions.
Upvotes: 2