Closed kcharter closed 4 years ago
@kcharter As you suggested, I've added & moved code to address the 2nd parameter, day, when it is typed as command-line argument.
OK, the new code in commit 230b5bfdbb767e52856e87f12a662e7ba412c139 looks good.
Let me know if you would prefer me to close this or if you would like to.
I have found that if you give the directory as the first command-line argument, but don't give a second command line argument, the script won't move any files. In the code
https://github.com/kimlew/bash-sort-images/blob/16847406d5bedc500235cf93c761493c8a512b7d/sort_images.sh#L29-L32
you try to initialize variables from command-line arguments. You do this even if there is only one command-line argument, in which case you'll set
day_subdir_also
to an empty string.Down in your loop, you check for an empty
day_subdir_also
, but if it's empty you never give a new value tonew_dir_and_filename
. Themv
command at the bottom of the loop then fails for every file with aNo such file or directory
error message.Just a suggestion: down in your loop you have an elaborate case statement that tests all the possible values for
day_subdir_also
. I suggest that you check for the all the possibilities outside your loop, and create asafe_day_subdir_also
variable whose value is guaranteed to be either'y'
or'n'
, and which you will use in your loop instead ofday_subdir_also
. The value should be'y'
if$day_subdir_also
matches[yY] | [yY][eE][sS]
'n'
if$day_subdir_also
matches[nN] | [nN][oO] | ''
(note the third case for the empty string)That way down in the loop the
case
statement on$safe_day_subdir_also
will be simpler and you can remove the check for whether$day_subdir_also
is empty.