从变量中去除前缀​​ - bash

Strip prefix from variable - bash

将 shell 脚本 (/bin/bash) 添加到自动化工作流程(复制文件路径)我想用它从变量路径中去除常量前缀 '/Volumes/'正在复制到剪贴板。

EG复制文件路径工作流程将'/Volumes/GRAID/audiovideo.mov'复制到剪贴板,我要粘贴的路径是'GRAID/audiovideo.mov'

要从名为 foo 的 shell 变量中删除已知常量前缀 /Volumes/,您可以这样写:

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

(参见 the Bash Reference Manual, §3.5.3 "Shell Parameter Expansion"。)