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

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World