Strip prefix from variable - bash [duplicate]
Asked Answered
W

1

6

Adding a shell script (/bin/bash) to an automator workflow (copy file path) I want to use this to strip the constant prefix '/Volumes/' from the variable path which is being copied to the clipboard.

EG The copy file path workflow copies '/Volumes/GRAID/audiovideo.mov' to the clipboard, the path I desire to paste is 'GRAID/audiovideo.mov'

Windhover answered 5/11, 2015 at 15:0 Comment(0)
D
8

To remove a known constant prefix /Volumes/ from a shell variable named foo, you can write:

foo="${foo#/Volumes/}"

(See the Bash Reference Manual, §3.5.3 "Shell Parameter Expansion".)

Donn answered 17/3, 2016 at 0:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.