Q:

Mac Bash: how to combine the open and str subtract to one line code?

new to bash , I use the following code to open the super folder with a file path.
function openUp(){
  cd $(echo $1 | sed 's@\(.*\)/.*@\1@' );
  open ..
}

like drag a file to terminal, then open the super folder conveniently.

openup /Users/de/Downloads/32/S01E32-array-arrayslice-collection-collections-1-master.zip  

How to combine the two line code to one line? 
I originally think open directly without changing directory.

A:

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@' <<< "$1")/.."
}

The basic improvements:

Instead of echo "..." | cmd, use here strings: cmd <<< "..."
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.

