📌  相关文章
📜  获取当前工作目录 powershell - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:11:51.924000             🧑  作者: Mango

获取当前工作目录 powershell - Shell-Bash

当编写 Powershell 或 Shell 脚本时,了解当前工作目录是非常有用的。在本文中,我们将讨论如何使用 Powershell 和 Shell-Bash 获取当前工作目录。

Powershell

在 Powershell 中,获取当前工作目录很简单。使用 Get-Location 命令,该命令将返回当前工作目录的路径。

PS C:\Users\user> Get-Location
C:\Users\user
Shell-Bash

在 Shell-Bash 中,获取当前工作目录也很容易。使用 pwd 命令,该命令将返回当前工作目录的路径。

$ pwd
/home/user

注意,在某些情况下,可能需要根据环境变量和别名重新定义 pwd 命令。因此,为确保脚本在不同环境中的兼容性,请使用 $(pwd)。该命令将在不同情况下返回正确的工作目录。

$ echo "当前工作目录是 $(pwd)"
当前工作目录是 /home/user

现在,您已经学会如何在 Powershell 和 Shell-Bash 中获取当前工作目录了。希望本文对您有所帮助!