sh Scripting - String Manipulation

Paul Schmehl pauls at utdallas.edu
Fri Oct 14 09:27:46 PDT 2005


--On Friday, October 14, 2005 08:39:04 -0700 Drew Tomlinson 
<drew at mykitchentable.net> wrote:
>
>
> That's a good idea (and something else I never thought of) if I wanted
> all the files, not just the *.jpg files.  And as I'll explain below, I
> intend to expand this script to work with additional directories where I
> might just want the *.mp3 or the just the *.avi, *.mpg, etc.  My thought
> was to build a script and run it through cron to keep the symlinks
> updated.
>
OK.  Then I think you're going about it the wrong way.

This would accomplish what you want without having to do any string 
manipulation, and without having to generate a list of files.  The for loop 
does all that for you.

for files in /my/dir/for/files/*.jpg
do
NEWFILES=`$files | cut -d'/' -f 6`
ln -s $files /new/dir/for/pics/$NEWFILES
done

Before you put the symlink line in the script, you'll want to echo 
$NEWFILES so you can make sure you're cutting at the right place. 
(Practice on the commandline so you can see what cut is doing.)

Paul Schmehl (pauls at utdallas.edu)
Adjunct Information Security Officer
University of Texas at Dallas
AVIEN Founding Member
http://www.utdallas.edu/ir/security/


More information about the freebsd-questions mailing list