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

Re: yet another bash question



On Tue, Nov 07, 2006 at 03:16:38PM +0000, Richard Lyons wrote:
> For things like saving photos to hard disk, I tend to use a few bash scripts
> to rename the files, keeping the numerical part and coding something else in
> place of the "cimg".  For example, I might change all the files cimg1234.jpg
> to cimg1299.jpg to be called foobar234.jpg to foobar299.jpg. I tend to
> modify these scripts when need arises, but the latest one shows an oddity I
> cannot understand.  
> 
> The script (called prep) is inline below. It removes $1 from the beginning
> of any filename in pwd and replaces it with $2, subject to a couple of
> sanity checks.
>  
> Here is the output from a test run:
> --------
> richard@scatola:~/test$ ls
> ohdear  ohwonderful  oops  oopsdeardear  tutdear
> richard@scatola:~/test$ prep oops wer
> 
> ... working
>     oops  ->  wer
>     oopsdeardear  ->  werdeardear
>             2 renamed --all done.
> 
> richard@scatola:~/test$ ls
> ohdear  ohwonderful  tutdear  wer?  werdeardear
> --------
> My question is:  where did the question mark come from? It always occurs if
> the whole filename is substituted.


I would guess one of two things, but just a guess:

1. all file names have some invisible character at the end of them
   that somehow gets stripped off by your script causing this artifact 

or

2. maybe more likely, there is a terminator character in your string
   you are using to mv to and its causing the artifact. 

Either way, I'd look into bash docs and see how it handles strings and
look for some little side-effect like that.

.02

A

Attachment: signature.asc
Description: Digital signature


Reply to: