split a string into path and application

The commands basename and dirname can be used for that, for example:

$ basename /home/user/a/directory/myapp.app 
myapp.app
$ dirname /home/user/a/directory/myapp.app 
/home/user/a/directory

For more information, do not hesitate to do man basename and man dirname.


With any POSIX shell:

$ str=/home/user/a/directory/myapp.app
$ path=${str%/*}
$ app=${str##*/}
$ printf 'path is: %s\n' "$path"
path is: /home/user/a/directory
$ printf 'app is: %s\n' "$app"
app is: myapp.app

save you for two processes forking.

In case of /myapp.app, myapp.app and /path/to/myapp.app, basename/dirname are more graceful. See also this question for more discussion.

Tags:

Split

Bash

Debian