Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script problem - not a directory

Status
Not open for further replies.

barakat

Programmer
Feb 25, 2002
2
US
I'm new in unix scripting, what i'm trying to to is set up
a script to to the following:
change file names such as {file 1} into {file_1},
{my file 1} into {my_file_1}
my script setup as:

in_file = 'ls -1'
for file in $in_file
do
if test -f "file"
then
n_check1='echo $file | sed 's/ */_/g'`
n_check2='echo $n_check1 | tr '[A-Z]''[a-z] |
sed 's/^_//g'`
n=1
while test -f "$n_check2"
do
nfile_name = $n_check2.$n
n='expr $n +1'
if test -f "$nfile_name"
then
nw_name = $nfile_name
fi
done
cp $file $nw_file
else
echo $file "is not a reqular file."1>&2
fi

done

when i run it from the command line as extra.sh
i get the message as extra.sh : not a directory.
please help thanks.


 
Actually I just wrote something like this, this week for anotehr post. Here is the script:

#!/bin/ksh
# Script to create a script to rename files with spaces in them.
Script="mv.ksh"
>$Script
for file in `ls|sed "s/ /_/g"` ; do
file1=`echo "$file"|sed "s/_/ /g"`
echo "mv '"${file1}"' "${file} >>$Script
done
echo "Script name is $Script"

When the script is done, execute the file named by $Script. You'll need to make it executable first.

Bill.
 
Why don't you simply do:
[tt]
cd /the/directory
for $FILE in *
do
NEWNAME=$(echo "$FILE" | tr ' ' '_')
echo "mv $FILE -> $NEWNAME"
mv "$FILE" "$NEWNAME"
done
[/tt]
?
I hope it works...
Unix was made by and for smart people.
 
That is the great thing about UNIX - multiple ways to accomplish the same goal. I guess that would be "fault tolerance" ?

BV :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top