Help with shell script move operation

chaoscreater

Active member
I have the following shell script and it works fine:

mv "/storage/emulated/0/Download/ReVanced Extended_v19.02.39_2024-02-05.txt" "/storage/emulated/0/1. My Stuff/1. Settings Backup"

However, I don't want to hardcode the source file (ReVanced Extended.....). I want to target anything .txt file that is "Revanced Extended", i.e I need to use a wildcard here. So I updated my script to the following:

source_dir="/storage/emulated/0/Download"
target_dir="/storage/emulated/0/1. My Stuff/1. Settings Backup"

for file in "$source_dir"/*"Revanced Extended"*.txt; do
if [ -e "$file" ]; then
mv "$file" "$target_dir"
echo "Moved: $file"
fi
done

However, it doesn't execute at all and there's no output. I've tried a couple of different ways to do this and the script just does nothing.

I have a few other shell scripts that does Copy and Delete operations and they work fine. But when it comes to the above, nothing happens.

And yes I know there is a built-in MacroDroid task for file operations, but I'm trying to use a single shell script in combination with a Dictionary variable. I just need to update the source and destination path in the dictionary variable, without having to create multiple MacroDroid file operation Actions. I have specific use cases for this, hence why I'm using a shell script.

And before you ask, I'm using root shell and have also tried it with the helper app. Again, no problem with these settings for other shell scripts except this particular one.
 

Endercraft

Moderator (& bug finder :D)
Wouldn't
Bash:
mv "/storage/emulated/0/Download/*Revanced Extended*.txt" "/storage/emulated/0/1. My Stuff/1. Settings Backup"
work? (notice the *)
 

chaoscreater

Active member
Nope it didn't work unfortunately.

I got it working after a lot of ChatGPT.
mv sdcard/Download/ReVanced\ Extended*.txt "/sdcard/1. My Stuff/1. Settings Backup/"

Can't put the source path in quotes, as * is treated as a literal string in the path instead of being treated like a wildcard. But if you have "ReVanced Extended" in the path, you need to put it in a string, which makes it a catch 22 situation. Trick is to keep source path without quotes and then escape the space between the words.
 
Last edited:
Top