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

Pete Slagle freebsd-questions at voidcaptain.com
Thu Apr 12 17:20:14 UTC 2007


Aitor San Juan wrote:

> 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.

man (1) realpath

For example:

 #!/bin/sh
 echo The full path of the file name is $(realpath $1)




More information about the freebsd-questions mailing list