Macos – OS X Command-line URL filter

command linemacos

I have a bash script that uses bash's "read" builtin to obtain a username and password from the user and then uses them as part of an AFP URL. I'm encountering some problems, however, when passwords contain characters that affect URL parsing (';' for example).

I've looked around for a command-line utility that can do URL-filtering but haven't found one. Does anybody know of such a utility? I would like to be able to do something like the following:

mount_afp "afp://`urlfilter $USER`:`urlfilter $PASS`@server.com".

Best Answer

You can use a simple one-line Python script to do this:

echo $USER | python -c 'import urllib; print urllib.quote(raw_input())'

Note that, while acceptable for your usage, urllib.quote is designed for use on URL components, not the entire URL. See #120951 for more.