开发者

Bash workingdirectory use as variable

开发者 https://www.devze.com 2023-01-08 07:37 出处:网络
I need to some homework ... The Question is : How can you print the path of the current directory (working di开发者_如何学Crectory) and how can you use it as a variable?

I need to some homework ... The Question is : How can you print the path of the current directory (working di开发者_如何学Crectory) 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 ?


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

echo "$PWD"


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消