简体   繁体   中英

Using cd in RedHat Linux script

I have a shell script that does some sed changes to HTML files. However, the cd commands don't seem to work... Even though I've used UNIX/Linux for ages, I'm sure this is a newbie question. See my code below.

However, if I take the for loop out and just make it stand on it's own (including the chmod command) and put the cd commands in a separate script with a line that calls the loop script like:

cd dir
/home/me/dothisscript
cd ../nextdir
/home/me/dothisscript
cd ../nextdir
/home/me/dothisscript
etc... etc...

It works...

This one below does not.

cd 1950
for i in *.html
do
   sed 's%TITLE%title%g' $i > t
   mv t $i
done
for i in *.html
do
   sed 's% - Removethis.com</title>%</title>%g' $i > t
   mv t $i
done
for i in *.html
do
   sed 's%<title>Removethis.com %<title>%g' $i > t
   mv t $i
done
for i in *.html
do
   sed 's%</title>% - Addthis.com</title>%g' $i > t
   mv t $i
done
exec chmod +x *.html
cd ..
cd 1960
for i in *.html
do
   sed 's%TITLE%title%g' $i > t
   mv t $i
done
for i in *.html
do
   sed 's% - Removethis.com</title>%</title>%g' $i > t
   mv t $i
done
for i in *.html
do
   sed 's%<title>Removethis.com %<title>%g' $i > t
   mv t $i
done
for i in *.html
do
   sed 's%</title>% - Addthis.com</title>%g' $i > t
   mv t $i
done
exec chmod +x *.html
cd ..
cd 1967
etc... etc...

Change

exec chmod +x *.html

to just

chmod +x *.html

exec replaces the shell process with the specified program, so the rest of the script never executes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM