home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 15823 < prev    next >
Encoding:
Text File  |  1993-01-21  |  1.5 KB  |  43 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews2.watson.ibm.com!yktnews!admin!watson!ranma.austin.ibm.com!channui
  3. From: channui@ranma.austin.ibm.com (Christopher Chan-Nui)
  4. Subject: Re: How does one change part of a file name in a shell script?
  5. Sender: @watson.ibm.com
  6. Message-ID: <1993Jan22.022441.56014@watson.ibm.com>
  7. Date: Fri, 22 Jan 93 02:24:41 GMT
  8. References: <C0uyI3.5sw@ichaos.nullnet.fi>
  9. Organization: IBM T. J. Watson Research
  10. X-Newsreader: TIN [version 1.1 PL8]
  11. Lines: 30
  12.  
  13. Juha Laiho (jlaiho@ichaos.nullnet.fi) wrote:
  14. : In article <RICHARD.93Jan14082457@ajax.stanford.edu> richard@ajax.stanford.edu (Richard Schiek) writes:
  15. : >So is there any way to take a file name in a shell script, chop off
  16. : >it's suffix and add a new one?
  17. : >
  18. : Try the 'basename' command. I think it's what you're looking for.
  19.  
  20. : f.ex:
  21. : basename foo.bar .bar        produces
  22. : foo
  23.  
  24. Or if you have a shell that supports it (csh, tcsh, and my favorite zsh) you
  25. could use Environment Variable Modifiers.  For example:
  26.  
  27. #!/bin/zsh
  28. NAME=$1:r
  29. tex ${NAME}.tex
  30. dvips ${NAME}.dvi
  31. lpr ${NAME}.ps
  32. rm ${NAME}.ps
  33.  
  34. You'd probably want to do some error checking or something though (so it
  35. doesn't continue when tex fails with millions of errors. :)
  36.  
  37. Hope this helps.
  38.  
  39. ---
  40. Christopher Chan-Nui    | The higher the "higher-ups" are who've come to see   
  41. channui@austin.ibm.com  | your demo, the lower your chances are of giving a    
  42. #include <disclaimer.h> | successful one.                                      
  43.