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