Strip prefix from variable - bash [duplicate]

丶灬走出姿态 提交于 2019-12-02 00:10:50

问题


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'


回答1:


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".)



来源:https://stackoverflow.com/questions/33547904/strip-prefix-from-variable-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!