11.8k views
2 votes
What is the difference in output between these two commands:

A) echo the working directory is pwd``
B) echo the working directory is $(pwd)

1 Answer

3 votes

Command A prints "the working directory is pwd" as it treats `pwd` as a literal string. Command B, using `$(pwd)`, correctly displays the current working directory in the output.

There is a difference in the output between the two commands:

A) `echo the working directory is pwd`

In this command, `pwd` is not enclosed within a command substitution syntax (`$(...)`), so it will be treated as a literal string. The output will be "the working directory is pwd."

B) `echo the working directory is $(pwd)`

Here, `$(pwd)` is a command substitution that executes the `pwd` command and replaces it with its output. The output will be "the working directory is [current working directory]."

In summary, option B will correctly display the current working directory, while option A will literally print "pwd" instead of the actual working directory.

User AshB
by
8.1k points