1831308 Members
3291 Online
110023 Solutions
New Discussion

About the shell script

 
juno2
Super Advisor

About the shell script

Sorry to post a new question again there, but I really want a solution .

I have a script which can compile a file ( eg. file1.cdr ) , the compiled file is .cbt extension ( eg. file1.cbt ) , how can I mv the compiled file (file1.cbt not file.cdr.cbt ) to the other path ( from /tmp to /usr) ? thx.

$pwd
/tmp
$my_script file1.cdr
$pwd
/usr
$file1.cbt
6 REPLIES 6
Mark Grant
Honored Contributor

Re: About the shell script

#!/bin/sh

FILE=`basename $1 .cdr"
compile $1
mv /tmp/$FILE.cbt /usr

This assumes you start the script with something like

myscript myfile.cdir

Also, the "compile" bit is where you do your compile with whatever command you use.
Never preceed any demonstration with anything more predictive than "watch this"
juno2
Super Advisor

Re: About the shell script

It is great , thx much for help.
juno2
Super Advisor

Re: About the shell script

thx reply ,

but I still have a problem , I don't know why even the program can't be compiled ( some compile error gerenated ), it still report the result is "0" , so it is not work to use the error checking function " if [ $? -eq 0 ] then .. " , could suggest is there other method to make sure the file will be copy only when the compilation is successful ? thx.
Mark Grant
Honored Contributor

Re: About the shell script

juno2

You'll have to find out in the script, the same way as you do yourself. If the compile produced an error somewhere you'll have to look for it. As an example, suppose the compile writes lots of stuff to the screen and then "ERROR, it didn't work too well" if there is a failure. You would do something like this

your_compile_command > /tmp/compile.log
grep ERROR /tmp/compile.log > /dev/null || {
your_copy_commands here
exit
}
echo "Couldn't copy because the compile broke again"
Never preceed any demonstration with anything more predictive than "watch this"
juno2
Super Advisor

Re: About the shell script

thx Mark reply, however,

the system will not generate the word "ERROR" , it will generate different words , not exactly the same , do you have other idea ? thx.
Mark Grant
Honored Contributor

Re: About the shell script

juno2,

You could try it the other way around. If it produces no output if it is successful then you you could test for success (nothing in the log) instead of failure (something in the log). Otherwise, I don't think there is much you are going to be able to do.
Never preceed any demonstration with anything more predictive than "watch this"