Try the 'basename' command. I think it's what you're looking for.Quote:>So is there any way to take a file name in a shell script, chop off
>it's suffix and add a new one?
f.ex:
basename foo.bar .bar produces
foo
..Wolf
Try the 'basename' command. I think it's what you're looking for.Quote:>So is there any way to take a file name in a shell script, chop off
>it's suffix and add a new one?
f.ex:
basename foo.bar .bar produces
foo
..Wolf
I want a simple shell script that takes a file, runs it through TeX
then dvips and prints the resulting postscript file, i.e. the command
``tex-print myfile.tex'' should run the following commands:
tex myfile.tex
dvips myfile.dvi
lpr myfile.ps
The problem I have is that if I pass ``myfile.tex'' to a shell script
``tex-print'' as a command line variable then $1 = ``myfile.tex'' so a
simple script like
tex $1
dvips $1
lpr $1
won't work. Also, the program that calles ``tex-print'' passes the
full file name ``myfile.tex'' and can't be configured to just pass
``myfile'' without the suffix.
So is there any way to take a file name in a shell script, chop off
it's suffix and add a new one?
Thanks for your help
Rich Schiek
---------------
Home Phone: (825)356-1084
.------------------------------------------------.
\ | No one born alive can know everything , | /(
||=:| All you want might be got through your effort. |:====================||||
/ | Hard-working can help yet . | \(
| Don't give it up , guy . |
`------------------------------------------------'
---------------
--
---------------
Home Phone: (825)356-1084
.------------------------------------------------.
#!/bin/sh
PATH=/usr/bin:$PATH
ARG="myfile.tex"
BASE=`basename $ARG .tex`
# BASE is now 'myfile'
DVI=$BASE.dvi
PS=$BASE.ps
echo $ARG $BASE $DVI $PS
Will output:
myfile.tex myfile myfile.dvi myfile.ps
Graham Rule
---------------------------------------------------------------------------
Edinburgh University, JCMB, Phone: +44 31 650 4989 O=Edinburgh;
Kings Buildings, Mayfield Road, Fax: +44 31 662 4712 P=uk.ac;
Edinburgh EH9 3JZ, Scotland A= ; C=GB
: 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
#include <disclaimer.h> | successful one.
1. Is there a shell script that can change files names with spaces to underscores?
I have been trying to write a script that can rename files that have
spaces and convert them to underscores. It seems that if I use a for
loop and use a $file variable the mv command only sees that variable up
to the first space and I am then stuck. Is there anything else that I
can do?
2. Dumb terminal over parallel line in Linux
3. Shell script acting as interactive shell - $0 not script name??
5. Extracting part of file name in bash script
7. How to write a shell script to obatin first NIC name?
9. how to find /dev/<part> from name of file in <part>
10. How to write a shell script to obtain the first NIC name ?
11. bash script to change file names in a directory?
12. Create file name in shell script
13. c-shell, changing the names for all the files containing a given string