Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 11 Dec 1998 13:43:42 -0600 (CST)
From:      "Paul T. Root" <proot@horton.iaces.com>
To:        jataylor@lundahl.com (James A. Taylor)
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Recursing directories?
Message-ID:  <199812111943.NAA05604@horton.iaces.com>
In-Reply-To: <36716768.BBCAEA1@lundahl.com> from "James A. Taylor" at "Dec 11, 98 11:41:44 am"

next in thread | previous in thread | raw e-mail | index | archive | help
In a previous message, James A. Taylor said:
> First of all thanks to Paul for his help with the mv command.
> 
> Is it possible to have a shell script recurse a directory tree?
> Still the same situation as my last email I have a directory tree
> with .shtml files.  I want to recurse the directory tree renaming
> each .shtml to a .html file. Paul sent me the following script that
> allows me to mv all .shtml in a single directory:
> 
> #!/bin/sh
> for i in *.shtml
> do
>     j=`basename $i .shtml`
>     mv $i $j.html
> done
> 
> This script works and changes all of the .shtml in the current
> directory.  Is their a way I can get the script to recurse my
> directory tree?

sure, name it nos (or some such).

#!/bin/sh

for i in *
do
	if [ -d $i ];then
		cd $i	
		nos
		cd ..
	else
		echo $i |grep ".shtml$" >/dev/null
		if [ $? -eq 0 ]; then
			j=`basename $i .shtml`
			mv $i $j.html
		fi
	fi
done


Ok, that's a little crude but it works. 
Be sure to have the script in your path and
be executable.

		



-- 
The only thing that makes life worth living is the willingness to risk
everything. Unless you risk everything, you don't have a life.
                       -- Roger Payne      

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812111943.NAA05604>