0

To get a file in my cwd in python I can do:

import os
cwd = os.getcwd()

filename = 'file.txt'
path = os.path.join(cwd, filename)

How would I do the same in a shell script?

David542
  • 104,438
  • 178
  • 489
  • 842
  • Also how to [get your working directory](http://stackoverflow.com/questions/8635456/how-do-you-get-the-current-working-directory-in-bash) – Cory Kramer Sep 29 '14 at 21:00

1 Answers1

4

The current working directory can be obtained in bash with the command pwd.
Usually, the variable $PWD contains the directory. So something like that should do:

full_path="${PWD}/foo.txt"

and by calling the pwd command:

full_path="$(pwd)/foo.txt"
fredtantini
  • 15,966
  • 8
  • 49
  • 55