New to bash scripting, and just need a little help.I've been testing this on a simple directory structure.I'm trying to change any directory and/or sub directory with the name Season to Sn.I got to a point where the script would change what I wanted...except for the top directory, as seen in the list below - Season 1 Season 2 Season 3.Directory structure:. AnotherShow  Sn1  Sn2  Sn3  Sn4 Movie1  Sn1  Sn2 Movie2  Sn1  Sn2  Sn3  Sn4 Movie3  Sn1  Sn3 Movie4  Sn2  Sn3 Season 1 Season 2 Season 3 Show  Sn1  Sn2  Sn3  Sn4  Sn5 TV     Sn1     Sn2     Sn3     Sn4My script is:array=$(find . -maxdepth 2 -type d -iname 'Season*' -print); # A more refined way to search for Seasons in    a directory.for dir in ${array[@]}; do # Put this list into an array.  Surround the array with quotes to keep all space   s (if any) together.   new=$(echo $dir | sed -e 's/Season 0/Sn/' -e 's/Season /Sn/'); # Only change Season 0 to SN.  Leave othe   rs alone.   sudo mv -v $dir $new && echo Changed $dir to $new; done                                                           
Renaming directory bash script - target ... No such file or directory
bash;scripting;file management
The issue is that you are not creating an array, you are creating a string. You can test this quite easily by attempting to print the first element of your array:$ array=$(find . -maxdepth 2 -type d -iname 'Season*' -print); $ echo $array./Season 3 ./Season 1 ./Season 2Looks good right? But if that were an array, you would be able to print each element separately. Unfortunately, the above is a simple string1 and not an array:$ echo ${array[0]}./Season 3 ./Season 1 ./Season 2$ echo ${array[1]}The array actually consists of a single string which is why the second element of the array (${array[1]}) is empty. In any case, you don't need an array for this, just read through the output of find (you also don't need the -print, that's what it does by default). A working version of your script could be:#!/usr/bin/env bashfind . -maxdepth 2 -type d -iname 'Season*' | sort -r |while IFS= read -r dirdo     mv $dir ${dir/Season /Sn} && echo Changed $dir to $dir/Season /Sn}; doneThere are a couple of tricks used there. First, the while loop to go through the results of find. This is the same basic principle as the for loop that you used but combined with read can read from standard input. The IFS= is needed to avoid splitting on whitespace (without it, the directory Season 1 would be split into Season and 1). The -r of read tells it to not allow backslashes to escape characters (things like \t and \n are treated literally) which makes sure this can deal with even the strangest names.   The sort -r is needed so that if you have a directory matching the pattern inside another matching directory, the child is listed before the parent. For example:./Season 12/Season 13./Season 12This ensures that you run mv Season 12 Sn12 after running mv  Season 12/Season 13 Season 12/Sn13. If you don't do that, the second command will fail since Season 12 no longer exists. Finally, I removed the sudo. You should instead run the script as sudo script.sh. It is never a good idea to have random sudo calls in your scripts. 1I'm not sure about the details but apparently, bash treats string variables as arrays of one element. 