Mailinglist Archive: opensuse-programming (98 mails)

< Previous Next >
Re: [suse-programming-e] Simple question about shell scripting on SuSE 8.0
  • From: Jerry Feldman <gaf@xxxxxxx>
  • Date: Thu, 5 May 2005 08:30:29 -0400
  • Message-id: <200505050830.30010.gaf@xxxxxxx>
On Thursday 05 May 2005 2:37 am, robert guru wrote:
> Hallo,
> I m a shell scripting newbie, and i m trying to create a shell script
> that search for some files named 'script', those files are located in the
> subdirectory of a directory named "folder", and for each file founded, i
> have to show the directory (full path) where the file was founded and
> pipe the file to some program.
> the script must be something like that:
>
> for each file found in the subdirectory tree of "folder"
> do
> "show the full path where the file was found, without the file name,
> like /root/folder/images"
> enter this directory already showed ($cd directory)
> "pipe the file to a program"
> done
A patrick mentioned, find should work, but here is a bash script that does
what you want. The script is not very elegant as I threw it together.
In this case, sname is a variable containing the name of a file that has
"script" in the name.
#!/bin/bash
for i in $(ls -p)
do
case $i in
*/) cd $i; pth=$PWD;
for sname in $(ls)
do
case $sname in
*script*) echo "$sname found in $pth";;
esac
done
cd ..;;
esac
done

--
Jerry Feldman <gaf@xxxxxxx>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9

< Previous Next >
References