このようなものに?
#set a variable saving the filename but not path of a file.
MY_FILENAME=$(basename $filename)
echo $MY_FILENAME >> /directory/log
mv $MY_FILENAME /diectroy/.
# DO STUFF HERE
# to your file here
#Move the file to the PWD.
mv /directory/${MY_FILENAME} .
unset $MY_FILENAME
#unseting variable when you are done with them, while not always
#not always necessary, i think is a good practice.
逆に、ファイルを PWD ではなく元の場所に戻したい場合、2 番目の mv ステートメントは次のようになります。
mv /directory/${MY_FILENAME} $filename
さらに、スコーピングの問題が原因で、元に戻すときにローカル変数を使用できず、ファイルからそれを読み取る必要がある場合は、次のようにする必要があります。
#set a variable saving the filename but not path of a file.
MY_FILENAME=$(basename $filename)
echo "MY_FILENAME = " $MY_FILENAME >> /directory/log
# I'm tagging my var with some useful title so it is easier to grep for it later
mv $MY_FILENAME /diectroy/.
# DO STUFF HERE
# to your file here
#Ive somehow forgotten my local var and need to get it back.
MY_FILENAME=$(cat /directory/log | grep "^MY_FILENAME = .*" | awk '{print $3}');
#inside the $() a cat the file to read it
# grep on "^MY_FILENAME = .*" to get the line that starts with the header i gave my filename
# and awk to give me the third token ( I always use awk over cut out of preference, cut would work also.
# This assumes you only write ONE filename to the log,
# writing more makes things more complicated
mv /directory/${MY_FILENAME} $filename
unset $MY_FILENAME