I'm running a Bash script that's buried in a directory on my system. I need to be able to get the first section of the directory path.
The path returned by
$0 in my script is as below. The "path/to/script" section is constant; the "/variable/path/to/folder" is permanent.
I need the underlined section. I've tried
cut -d/ -f-4 and
cut -d/ -f4-, but
cut indexes from the front of the path, and I need to index from the back. (I don't know how many levels will be between
main-folder, but I do know how many will be between
my-script.sh. The path here is accurate: there are two folders in
main-folder before you get to