我写了以下脚本:
clear-host
## Step 1 (Creating 2 command line variables)
##########################################################################################################################
Clear-Host
$WorkingDirectory = $ARGS[0]
$DirectoryName = $ARGS[1]
##Step 2 (Check if variables are empty and get user input if necessary)
##########################################################################################################################
if ("$WorkingDirectory" -eq "")
{
Write-Warning "Parameter Required"
$WorkingDirectory = Read-Host "Enter the absolute path to working directory "
}
if ("$DirectoryName" -eq "")
{
Write-Warning "Paramater Required"
$DirectoryName = Read-Host "Enter a directory name to search for in $WorkingDirectory "
}
for ($i=0; $i -le 2; $i++) {write-host ""} # to print 2 blank lines using for loop
##Step 3 (Test to see if PWD is equal to $WorkingDirectory and if not move the location )
##########################################################################################################################
if ("$PWD" -ne "$WorkinDirectory")
{
write-host "You are not in the < $WorkingDirectory > . Do you wish to move? Press CTRL+C to exit or wait"
write-host ""
pause
Set-Location -Path $WorkingDirectory
}
##Step 4 (Test to see the directory exists in the working directory or not )
##########################################################################################################################
if((Test-Path $DirectoryName) -ne "True")
{
write-host "Directory $DirectoryName does not exist"
}
我在第3步遇到的问题。它应该使用$ WorkingDirectory变量检查我的当前位置,如果它们不相同则位置将被更改。但问题是即使我和$ WorkingDirectory在同一个位置,它仍然给我警告信息。如何解决