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
  • 829
  • 1
  • 9
  • 20

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 Quénot
  • 173,512
  • 41
  • 224
  • 223
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
  • 107,652
  • 25
  • 181
  • 264