As @kps mentioned in a peer comment, using the built-in ex[0] '!' command can do what the vim script above does.
For example, to execute the line where the cursor is currently placed and replace the same line's content using POSIX shell:
:. !sh
To do the same with multiple lines I like to mark the first command, then the last, and run: :'a,'b !sh
Where the "a" buffer is the first command and the "b" buffer is the last command in this example. There are many other ways to specify ranges too. I recommend beginning with vim's builtin help: :help range
And going from there.0 - https://man.freebsd.org/cgi/man.cgi?query=ex&apropos=0&sekti...