Ads

how to fetch file name ?

in bash script or linux terminal

%%bash

basename /home/abanoub/Work/hello.py

hello.py

in Python 3

%%python3

from pathlib import Path

p = Path('/home/abanoub/Work/hello.py')

print(p.name)

hello.py

or

%%python3

p = '/home/abanoub/Work/hello.py'

print(p.split('/')[-1])

hello.py

in Perl

perl -E'say"/home/abanoub/Work/hello.pl"=~s{.*/}{}r'

or

perl -MFile::Basename -E'say basename"/home/abanoub/Work/hello.pl"'

If you want to get new posts, make sure to subscribe to Value In Brief by Email.