Bash find and move files with '[ ]' in name
Part of a bash script I'm making involves rar splitting files and then moving the split files to another directory once they are done.
So if I have a file like "test file.txt", it would first get rarred to "[test] file.t开发者_高级运维xt.part1.rar", "test file.txt.part2.rar", and then both of the rar's would get moved to another directory.
I have the rar bit working fine, but i'm having trouble on the find & move.
Here's my script:
#!/bin/bash
# [...]
rar a -m0 -v104857600b "$1.rar" "$1";
find $folder -name "$1.part*" -exec mv {} $someotherfolder \;
However it doesn't seem to be working. I've tested that find one liner from the shell and I'm guessing the problem is because the files have parenthesis in the names -> "[" and "]"
What do you guys think?
'[' and ']' are used in shell to describe sets of characters. You have to escape them with '\' to get the correct behavior. If you do not escape them you tell find to look for files with 't' or 'e' or 's' or 't' :)
To do that with the parameter $1, you have to use something like :
param=$(echo $1 | sed 's@\[@\\[@g'| sed 's@\]@\\]@g')
and use '$param' instead of '$1'
my 2 cents
精彩评论