I don't understand the error in my bash script. #!/bin/bashnewFile=for file in *do    newFile={$file/ /_}     # so as to replace spaces with underscores    mv {$file} {$newFile}doneIt complains that newFile is not a command in the line newFile={$file/ /_}I guess I'm doing things wrong, but I keep stumbling on that point.
Replace spaces by underscores in files: Error in my bash script
bash;variable
You need to move the position of the $ and add a last / to the sub to perform it for all spaces. You also need to quote the variables as it will see the space in the filename as a delimiter between the arguments for mv.#!/bin/bashnewFile=for file in *do    newFile=${file// /_}     # so as to replace spaces with underscores    mv {$file} {$newFile}doneAlthough as stated in the other answer, half of this script is redundant.newFile=Is not needed at all as the variable can be first referenced in the assignment later on. newFile=${file// /_}Although the assignment itself is also not needed as the parameter substituion does not alter the original.So it can be rewritten as #!/bin/bashfor file in *do    mv ${file} ${file// /_} done