Stacker
Stacker

Reputation: 167

mv command not working in shell script NO SUCH FILE

I am using a sh script to try to update fields in source control. However, when I go to run the command i get he error:

 mv: cannot stat 'tmp': No such file or directory

I have a tmp file created, and it is supposed to populate with the issueNumber and replace the specified field with yes.

Here's my code as it stands:

issueNum=$1
field=$2
newValue=$3
typeset -A fidMap
# fidMap['type']=7
#fidMap['customerName']=63
#fidMap['patchNum']=58
#fidMap['releaseImplmntdIn']=42
fidMap['state']=5
#fidMap['subsystem']=13
#fidMap['changeRequestNumber']=36
#fidMap['releaseFoundIn']=39
#fidMap['System']=35
#fidMap['assignedTo']=14
if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then 
    echo "Please pass in three variables: issueNumber field value"
    echo "Example: new_mod_value.sh 10003 state Approved"
    return 0
fi
echo "issue number $issueNum"
echo "field is $2"
echo "value is $3"
rm runIssue.xml
echo "<queryIssue issueDB=\"TEOCO\" expandUsers=\"true\">" > runIssue.xml
echo "1 == $issueNum" >> runIssue.xml
echo "</queryIssue>" >>runIssue.xml

 accurev xml -l runIssue.xml > issuesOutputtmp.xml
 currentFile=issuesOutputtmp.xml
sed 's/<issues>/<modifyIssue issueDB="TEOCO">/' $currentFile > tmp && mv  tmp $currentFile  
sed 's/<\/issues>/<\/modifyIssue>/' $currentFile > tmp && mv tmp $currentFile
sed 's/fid="2">[0-9]*<\/transNum>/fid="2"><\/transNum>/' $currentFile > tmp && mv tmp $currentFile
grep "<$field" $currentFile >/dev/null
if [ $? -eq 0 ]; then
 SED_ARG=" 's/fid=\"${fidMap[$field]}\">.*/fid=\"${fidMap[$field]}\">$newValue<\/$field>/' $currentFile"
 eval sed $SED_ARG > tmp && mv tmp $currentFile
else
  SED_ARG=" 's/<\/issue>/<$field\
    fid=\"${fidMap[$field]}\">$newValue<\/$field>\
 <\/issue>/' $currentFile"
  eval sed $SED_ARG > tmp && mv tmp $currentFile
fi
#Escaping and cleanup
mv tmp $currentFile
sed 's/&/,/g' $currentFile > tmp && mv tmp $currentFile
#sed 's/</&lt;/g'$currentFile > tmp && mv tmp $currentFile
#sed 's/>/&gt;/g' $currentFile > tmp && mv tmp $currentFile
#sed 's/"/&quot;/g' $currentFile > tmp && mv tmp $currentFile
#sed 's/[^!-~\s]//g' $currentFile > tmp && mv tmp $currentFile
 accurev xml -l $currentFile

Any help would be appreciated! Thanks

Upvotes: 0

Views: 470

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409166

You create the file tmp in a lot of places, and directly afterwards rename it as something else. That means there will not exist a file named tmp when you have your lonely

mv tmp $currentFile

Upvotes: 1

Related Questions