linux - Bash renaming from path variable -
i'm doing "recycle bin" type script, have done if file exists try restore file want let user choose new name file restored as, have full path file deleted in variable $f1 dont know how go changing file name here
#!/bin/bash trashcan ="/home/alihassan/desktop/trashcan" cd $trashcan f1=$( grep "$1" storage.txt ) if [ -f $f1 ] echo "file exists @ restore location, please enter new filename" read ans mv "home/alihassan/desktop/trashcan/$1" "$f1/$ #issue here else mv "/home/alihassan/desktop/trashcan/$1" "$f1" fi
on face of it, might after:
mv "$trashcan/$1" $(dirname "$f1")/"$ans"
this preserves original path $f1
except last component, , uses answer in place of last component.
Comments
Post a Comment