[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: A quick Q: how do I command something in large amount



On Fri, Sep 16, 2011 at 12:47:11AM +0800, lina wrote:
> > > You have options.
> > Just some additional remarks:
> > a) the for-loop won't work, as "FILE" is expanded to the name including
> >   the .txt, so if you have a file "a.txt" this loop will execute
> >           mv a.txt.txt a.txt.pdf
> >   You need instead
> >     for FILE in *.txt; do mv $FILE `basename $FILE .txt`.pdf; done
> >   in order to remove the ".txt" from the variable "$FILE"
> >
> 
> Seriously, I have problem testing this one,
> 
> the come out is like:
> 
>  (basename $FILE .txt.pdf
> 
> sorry I might be so sleepy, I will check another time,
You probably typed a mixture with the solution from Aaron :-)
I think the opening parenthesis "(" CAN'T stem from my line -- there
should be no "(" 
In fact, I use just a different syntax then Aaron to achieve the same
result: We want to evaluate the command "basename $FILE .txt" and pass
the output of this command as argument to mv (this feature is called
"command substitution" in the man-page).
Now, there are two ways to achieve this in bash:
1) use $(...)
2) use `...` 
There are only some minor difference how a backslash is treated within
$(...) and `...`.

Axel


Reply to: