I wrote a small script that should rename some files in a directory for me.
#!/bin/bash
a=1
for i in *.jpg ; do
new=$(printf "%04d.jpg" "$a")
mv "$i" "$new"
let a=a+1
done
#end of file
After running the script is says this: "mv: command not found"
How come there are no error outputs when I run the code directly on the shell like this:
for i in *.jpg ; do new=$(printf "%04d.jpg" "$a") ; mv $i $new ; let a=a+1 ; done
It probably is a matter of PATH setting. The /bin
directory should be inside your $PATH
For debugging purposes, add
echo PATH is $PATH
at start of your script, and perhaps put #!/bin/bash -vx
as your script's first line. See this, execve(2), bash(1).
As a workaround, replace
mv "$i" "$new"
with
/bin/mv "$i" "$new"
See mv(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With