0

The shell script below creates a new file "foo.conf" with the content specified between the EOF tags.

#!/bin/sh
cat > foo.conf << EOF
DocumentRoot "./search.bin"
EOF

The created file contains the following content:

DocumentRoot "./search.bin"

But I need to have the full path of the current directory instead (where my shell script resides), for example:

DocumentRoot "/home/me/search.bin"

Is this even possible? Thanks in advance.

Mohammad Fneish
  • 621
  • 1
  • 7
  • 14

2 Answers2

1

Use this :

#!/bin/sh
cat > foo.conf << EOF
DocumentRoot "$(readlink -f ./search.bin)"
EOF

You can replace

readlink -f

by

realpath   
Gilles Quenot
  • 154,891
  • 35
  • 213
  • 206
0

Heredocs with an unquoted first word allow for pretty much full variable and other expansion. So you can do

#!/bin/sh
cat > foo.conf << EOF
DocumentRoot "$(pwd)/search.bin"
EOF
Mad Physicist
  • 95,415
  • 23
  • 151
  • 231