Link to home
Create AccountLog in
Avatar of integrosys
integrosys

asked on

Extract file name from full-path name

I have a script, say test.sh, that takes in the full-path name of a file as parameter, say /export/home/xxx/myfile.pdf. Inside this script, I want to extract out just the file name (myfile.pdf) from this full-path name, and assign to a variable. How can I do that? Thanks!
Avatar of ozo
ozo
Flag of United States of America image

${parameter/*\/}
Avatar of integrosys
integrosys

ASKER

The parameter passed in is $1. So using your solution, it would be ${1/*\/}. But I am getting a " bad substitution" error.
ASKER CERTIFIED SOLUTION
Avatar of yuzh
yuzh

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
some shells may prefer
${1##*/}