Re: C-Shell: How to append to filename?



Andrew wrote:
Hello, I am writing my first (C-Shell) UNIX script and I would like to
know how to rename each file in a directory by appending a _new to it.
For example, if I have in a directory the files:
apple
banana
catfish

Then I want, after program execution, for them to be:
apple_new
banana_new
catfish_new

So far I have this:
-
#!/bin/csh

foreach filename (`ls`)
mv $filename ????;
end
-
I don't know what to put in the ????, I'm not sure how to do dynamic
variable names. If anyone could let me know, I would thank them.

Regards!


foreach filename (`ls`)
mv $filename ${filename}_new;
end

BTW, use the fully qualified path for mv and ls. Any user can set an alias to completely change the basic function of any command.
Been bit by this one many times :)
.



Relevant Pages

  • Re: Changing Uppercase filenames into Lowercase
    ... > I already found MAKEUP.COM which breaks down a filename ... > uses the RENAME command to rename lowercase names and ... > lowercase filename. ... > The filename remains uppercase because DCL uppercases ...
    (comp.os.vms)
  • Re: Error 2471
    ... appending to a production table there is a way to check if Filename ... There must exist a table or query named "WOProduction". ... Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.formscoding)
  • Re: Trying to rename files in a folder from VBA
    ... The VBA Dir function lets you use wildcards, so assuming you know the name ... Dim rs As DAO.Recordset ... i.e. Column1 has the code and column2 contains the filename. ... I am using Access2003 and i am trying to rename all files in a folder ...
    (microsoft.public.access.forms)
  • Re: Renaming files using wildcards
    ... When I strip down the filenames of their ... spaces, the rename works well. ... strip the filename of it's spaces, ... rename command can't find the file name to rename when it ...
    (microsoft.public.windowsxp.general)
  • Re: remove words from mutiple files
    ... could edit those text files running Windows. ... That would be a good use for the rename feature if its in Ubuntu. ... # Checks if filename already lowercase. ...
    (alt.linux)