So I'm doing this exactly the way the tutorial tells me to, and something still doesn't work...
1 #!/bin/bash
2 users=$(ls *.usr)
3 date=$(date +%F)
4 for usr in $users
5 do
6 mv ${usr} ${date}-${users}
7 done
These are the contents of that directory:
1.sh fila2 fila6 file3 log1 marty1.usr marty5.usr marty9.usr user3
2.sh fila3 file0 file4 marty0.usr marty2.usr marty6.usr user0 user4
fila0 fila4 file1 file5 marty10.usr marty3.usr marty7.usr user1 user5
fila1 fila5 file2 file6 marty11.usr marty4.usr marty8.usr user2 user6
Now apparently, my script should rename all of the files that end in .usr to have the date in front of their name, but instead, I get this error:
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
mv: target ‘marty9.usr’ is not a directory
Again, I have no clue what I'm doing wrong, considering I didn't even ask it anywhere to make a folder called marty9.usr...
users=$(ls *.usr)
should be regarded as unreliable – steeldriver Aug 14 '18 at 14:56$(ls *.usr)
will cause problems with the subsequent loop if any of the filenames contains whitespace - see for example Why doesn't my loop over the output of ls work?. It may work in this case but it's a bad habit to get into. – steeldriver Aug 14 '18 at 15:06PATH="some string"
and then you script will be broken -- see https://stackoverflow.com/questions/28310594/ls-not-found-after-running-read-path – glenn jackman Aug 14 '18 at 15:11