Mac Bash: how to combine the open and str subtract to one line code?
You can use open with an absolute path, it doesn't have to be a relative path.

That is, you could write the same in one line, with some basic improvements:

openUp() {
  open "$(sed 's@\(.*\)/.*@\1@' &lt;&lt;&lt; "$1")/.."
}


The basic improvements:


Instead of echo "..." | cmd, use here strings: cmd &lt;&lt;&lt; "..."
Double-quote variables used as command line arguments (in your example, of cd, and echo
It's not recommended to use the function keyword, write without


A more important improvement would be to stop using sed to get the name of the base directory. Using a regex is error-prone and not as intuitive as the dirname command:

openUp() {
  open "$(dirname "$1")/.."
}


Notice that the arguments of dirname and open are both double-quoted,
as mentioned earlier.
This is necessary, to protect from word-splitting and globbing.