You don't need a regex. Bash supports simple glob patterns for trimming prefixes/suffixes. This can be done with ${1##*/}
, which trims everything up to the last /
from the variable.
Specifically, there are 4 variants:
${var#pat}
treatspat
as a glob and trims the shortest matching prefix fromvar
.${var##pat}
treatspat
as a glob and trims the longest matching prefix fromvar
.${var%pat}
treatspat
as a glob and trims the shortest matching suffix fromvar
.${var%%pat}
treatspat
as a glob and trims the longest matching suffix fromvar
.
In your specific case, you'll probably want to say
function jslint {
/usr/local/bin/node /usr/share/node-jslint/node_modules/jslint/bin/jslint.js "$1" > "~/Desktop/" + "${1##*/}" + "-lint.txt"
}
(I've also quoted the variable, which is necessary if the path contains spaces)