Question

I would like to write a bash script that returns the path of a mount point for a network mount on a Mac. What I've come up with so far is the following:

mount | sed -n -e "/^\/\/mynetaddr/s/\/\/mynetaddr on \([^ ]*\).*$/\1/p"

What this does is look for a network resource //mynetaddr and grab the mount point path from the mount command.

Is there a magic char, like &, that will match on an address regexp in sed? Alternatively, how do I rewrite the above so that I do not have to repeat the network address?

Was it helpful?

Solution

Just get rid of the address regex entirely:

mount | sed -n -e "s/\/\/mynetaddr on \([^ ]*\).*$/\1/p"

The s/// command will then be matched against every line of the input, and only those in which a replacement occurs will be printed out (because that's how the p flag works).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top