Problem renaming a file with single quotes

Hi,

I am trying to create a script which validates the incoming source files. The script has File name Pattern as Argument. The First part of the script validates if there are any files available

if [ -f $FILE_NAME ]
then
echo "\n Files are available to process \n"
else
echo "\n File does not exist: Process is Terminating \n"
exit 1
fi

I am receiving multiple files in the below format

'abc.def.ghi.jkl'
'abc.def.xty.xyz'
'abc.def.rew.ter'

I want to rename each of these files with out the single quotes as below

abc.def.ghi.jkl
abc.def.xty.xyz
abc.def.rew.ter

I am trying to do that using below code

for FILE_NAME in $FILE_NAME
do
mv "'$FILE_NAME'" "$FILE_NAME"

The Problem is when i am pass the argument with single quotes the mv command throws error.

I want to achieve 2 things
1.pass the argument(Filename) without the Single quotes by changing the internal code
2.Rename the files without the single quotes.

Please help.

Thanks,

Try this:

cd /working_directory
for filename in `ls`
do
   new_filename=`echo $filename| tr "'" " "` 
   mv $filename $new_filename
done

Or this:

for fn in *; do
  mv $fn ${fn//\'/}
done

or

for fn in *; do
  eval mv \$fn $fn
done

or perhaps more appropriate in this case :wink:

for fn in *; do
  eval mv '$fn' $fn
done

Its giving the below error

Usage: mv [-I] [-i | -f] [-E{force|ignore|warn}] [--] src target
or: mv [-I] [-i | -f] [-E{force|ignore|warn}] [--] src1 ... srcN directory

Does this work?

for fn in \'*\'; do
  mv $fn ${fn//\'/}
done

or

for fn in \'*\'; do
  eval mv \$fn $fn
done

or

for fn in \'*\'; do
  eval mv '$fn' $fn
done

all the three codes still want me to give the file name with single quotes as an argument ......is there anyway that i can do it with out giving the single quotes in the argument

# for file in *\'*\'*;do echo mv "$file" "${file//\'/}";done
mv my'.'file my.file

the code is giving a syntax error
0403-057 Syntax error at line 120 : `'' is not matched.

and when i closed it with a " it says
"${FILE//\'/}": 0403-011 The specified substitution is not valid for this command.

please take note that the ' has special meaning to the shell. to take the ' as a literal string, you should enclose the variable in double qoutes

mv "$filename" "$new_filename"

Unable to resolve will open a differnt thread with better Explanation.Closing this thread