Echo the basename in shell -


i have path directory , need extract filename out of can use further in shell script.

#!/bin/sh dir=/var/tmp/file1 fname= basename $dir  echo $fname echo "the script executes:" $fname  echo $fname 

here fname gets printed once. in other cases, comes blank.

where going wrong?

this below working.

#!/bin/sh dir=/var/tmp/file1 fname=`basename $dir` echo $fname echo "the script executes:" $fname echo $fname 

output $: ./tt.sh

file1

the script executes: file1

file1


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -