I have a fodler that contains file names that have spaces in them.
I have made a script that replaces the spaces and creates the new file name with _ instead of " " (space) and ran the mv command in the for loop.
This has not worked in script and giving me the below message.
Usage: mv [-I] [ -d | -e] [-i | -f] [-E{force|ignore|warn}] [--] src target
or: mv [-I] [-d | -e] [-i | -f] [-E{force|ignore|warn}] [--] src1 ... srcN directory
But if i debug the shell script and extract the mv command individually and run it,it does work fine without any issues.
The command that is generated looks like
mv "abc ddd eee.txt" abc_ddd_eee.txt
Could you please advise why the command when typed on unix box worked fine and not via script ?
Entire script:
for i in *
do
v1=$(echo $i|sed -e 's/^/"/g' -e 's/$/"/g' )
v2=$(echo $v1|sed 's/ /_/g'|
awk -F "[-.]" '{print $2,"_",$1,".",$3}'|
sed 's/ //g'|
sed -e 's/^_//g' -e 's/"$//g'|
sed 's/"//2' )
mv $v1 $v2
done