hi
actually i want to get fully qualified path name of the file when the file name is entered as command line argument while running a shell script
ex. if i run the shell as
$./test.sh ./nsdnet_file.csv
the it should display me the full path of the file like
/dialp/Release/bin/nsdnet_file.csv
Try something like:
full=$(pwd)${1#.}
echo $full
Regards
actually this will work only if the nsdnet_file.csv is in the same directory as the shell script.
what if the nsdnet_file is one dir ahead of the shelll script
like if we execute like
$./test.sh ../nsdnet_file.csv
then it should also give the correct path i.e /dialp/Release
#! /bin/bash
# filePath.bash
# (experimental)
INPUT=$1
FILE=$( basename $INPUT )
PATH=$( echo $INPUT | sed "s/$FILE//" )
PATH=$( cd $PATH && pwd && cd - > /dev/null 2>&1 )
echo $FILE
echo $PATH
exit 0
[house@discovery] pwd
/home/house
[house@discovery] sh filePath.bash ../this.file
this.file
/home
[house@discovery] sh filePath.bash /root/cron/that.file
that.file
/root/cron
[house@discovery] sh filePath.bash ../house/Desktop/no.file
no.file
/home/house/Desktop