Linux: Shell Script for Printing Full Path with Filename

Here is a shell script for printing full path with filename. Suppose you have given your shell script a file name=realpath then It will work like this:


$realpath filename.txt
/home/satya/filename.txt


$realpath folderName
/home/satya/f1.txt
/home/satya/f2.txt, etc

It just print files one level deep.

#!/bin/sh
#find $PWD -name $1 2>/dev/null
#find $PWD -name $1 2>&-
if test -d "$1"
then
    cd $1
    echo "Files in Dir: $1
        "
    for i in *
    do
            find $PWD -name "$i"; #Display File name
    done
else
    find $PWD -name $1 2>&-
fi
helpme () {
    echo "Give Filename or FolderName. It will output full path with fileName for file, Or
        all files one level deep of directory, if given directory name."
}
if [ "$1" = "--help" ]
then
    helpme
fi

Update: I have added command for help in above file. Now, if you do >realpath --help then it will show you help.