Shell scripting: Absolute path name of a file given as parameter

Garrett Cooper youshi10 at
Thu Apr 12 09:04:50 UTC 2007

Aitor San Juan wrote:
> Hi List,
> Just a simple question.
> I have developed a shell script that, among other things, shows the filename
> that was specified as a parameter.
> However, when I invoke the script and the file is located in the current working
> directory, it just shows: ./my_input_filename
> I'd like the script to show the full path name of the input file. I wonder
> whether there is or not an equivalent to %~f1 (Windows Batch file programming).
> This parameter extension expands parameter %1 ($1 in shell scripting jargon) to a
> Fully qualified path name.
> Any hint would be highly appreciated.
> Thanks in advance.
> Aitor.
You could always do it relative to the current working path, i.e. 

There's another way to do this by determining the absolute path of the 
shell script, but that was a bit more complicated and I don't remember 
where the documentation for that is right now..

More information about the freebsd-questions mailing list