I have this command from the question Can automation service to get the parent folder path? but it has spaces in it.

When it's ran it looks like this:

File Path: file:///Volumes/Desktop/Fortigate/Fortigate 200D/Policies.txt
Parent Folder: file:///Volumes/Desktop/Fortigate/Fortigate 200D

This is exactly what I wanted except that it has spaces and it needs to have %20 instead of the spaces in the file path.

Could someone show me how I would edit the shell script below to replace these spaces with %20?

toTheClipboard="File Path: file://$1 Parent Folder: file://$(dirname "$1")" pbcopy<<<"$toTheClipboard"

You can pipe to sed 's/ /%20/g' to replace spaces with %20.

toTheClipboard="File Path: file://$(echo $1 | sed 's/ /%20/g') Parent Folder: file://$(dirname "$1" | sed 's/ /%20/g')" pbcopy<<<"$toTheClipboard"
  • This was perfect... You saved my life today! Mar 5 '18 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .