tags:

views:

26

answers:

2

Hey there,

I need to some homework ... The Question is : How can you print the path of the current directory (working directory) and how can you use it as a variable?

The first part of the question is easly answered: pwd

But how can I use it as a variable ?

+1  A: 

In bash, you can execute a command and obtain the output using backticks, for example

paul@paul-laptop:~$ WORKING_DIRECTORY=`pwd`
paul@paul-laptop:~$ echo $WORKING_DIRECTORY
/home/paul

There is an alternate syntax too, using a dollar sign and brackets - WORKING_DIRECTORY=$(pwd)

Brabster
Cheers ! Very quick and correct answer :-)
Timothy
No problem, thanks for accepting!
Brabster
+2  A: 

Bash has a variable PWD which should be preferred over the pwd command:

echo "$PWD"
Philipp
`pwd` is a Bash builtin so the cost is low.
Dennis Williamson