I have a folder structure that looks like this /some/folder/1/some/folder/2...and a symlink current that links to one of the folders. Is it possible and when how to read the target of the link, increment the name of the last folder and create a folder with that number, e.g. read the link that points to /some/folder/2 so I know the last number is 2 and increment this number to create a new folder /some/folder/3 to store new files?I already have a script that reads the target of the link, but I have no clue how to get the last part of the path (the number) and increment it by one.
Read target of symlink and increment target by one
shell;scripting;symlink
use readlink to get the target of a symlink:target=$(readlink $1)then use the power of shell, to remove everything before the last /;id=${target##*/}or remove everything after the last /:base=${target%/*}then use the power of shell to do simple arithmeticnewid=$((id+1))finally glue them together:newtarget=${base}/${newid}or, in one line:newtarget=${target%/*}/$((${target##*/}+1))