I want to create a directory with a number at the end, e.x. "dir1", and increment that number if the directory already exists until it hits a directory name that doesn't exist, and I need to do this in a single line in a Linux command line, something like:
mkdir --increment dir$
How would I go about doing that?
So far I've got this:
dir=output; n=0; mkdir -p $dir$n; if test -d $dir$n; then n=$((n+1)); echo $dir$n; fi
But it just echos the next dir name, I need it to recursively execute the command.