In my current directory, I have multiple subdirectories that contain files. I'm trying to move those files from the subdirectories to my current directory. To this end, I've created this inline bash program:
for i in */ ; do for j in $f* ; do mv "$i$j" $PWD ; done ; done
When I run this program, however, I'm prompted by the correct use format:
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
I'd appreciate any clarification as to why this is happening.
Thanks!
$f
coming from? You should quote$PWD
. – pLumo Apr 19 '21 at 19:33do mv "$i$j" $PWD ;' it says 'do echo mv "$i$j" $PWD ;'
This may enlighten you as to why the script is doing what it is doing. Also, see this question to read why this is an important technique to avoid performing a slew ofmv
commands that are WRONG. – Jim L. Apr 19 '21 at 19:45i
andj
have and the value off
andPWD
. There are two plausible explanations, both covered by our reference question:PWD
contains special characters such as whitespace, or a value ofi
starts with a dash. If you can't figure out the problem after reading our reference question, edit your question to show all the file names involved and a full transcript of running your script underbash -x
, then flag your question and ask for it to be reopened. – Gilles 'SO- stop being evil' Apr 19 '21 at 20:29echo
s a series 100% correctmv
commands (and nothing else), all you have to do is pipe the output of your script to a shell likesh
orbash
, and the commands will be executed. So you have a built-in "dry-run" feature where you can see what the script is going to do, before it actually does it. – Jim L. Apr 19 '21 at 22:13