2

I wrote a bash shell script to rename the file,

#!/bin/bash

#renaming the files

for filename in 'find . -name "PostStackTemplate*"' 
do
   echo $filename 
   newName='echo $filename | sed -e "s/TestVersion/Version2/g" $filename'
   mv $filename  $newName 
done

When I execute this script, I am getting the output as

find . -name "PostStackTemplate*" 
mv: invalid option -- n 
Try `mv --help' for more information.

Am I doing something wrong.

1
  • 1
    If you actually used single quotes instead of backquotes, that's your problem. You want: for filename in $( find .... ) and newName=$( echo ... ) Commented Feb 8, 2012 at 0:03

1 Answer 1

2

I think you to use command substitution to assign the output of the sed command to the newName variable:

newName=$(echo $filename | sed -e "s/TestVersion/Version2/g" $filename)

Otherwise, newName would contain just the string being assigned.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.