Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将值从Foreach对象添加到三个不同的变量中_Powershell_Powershell 3.0 - Fatal编程技术网

Powershell 将值从Foreach对象添加到三个不同的变量中

Powershell 将值从Foreach对象添加到三个不同的变量中,powershell,powershell-3.0,Powershell,Powershell 3.0,我有一个文件(config.cfg),它有如下三个字符串:host:user:pass 在Unix代码中,我这样做是为了获取值并将其分配到三个不同的变量中: $FTP_HOST=$( cut -f1 -d: config.cfg ) $FTP_USER=$( cut -f2 -d: config.cfg ) $FTP_PASS=$( cut -f3 -d: config.cfg ) 如何在PowerShell 3.0中实现这一点?我试过使用Foreach对象,但找不到一种方法来分配

我有一个文件(config.cfg),它有如下三个字符串:
host:user:pass

在Unix代码中,我这样做是为了获取值并将其分配到三个不同的变量中:

  $FTP_HOST=$( cut -f1 -d: config.cfg )
  $FTP_USER=$( cut -f2 -d: config.cfg )
  $FTP_PASS=$( cut -f3 -d: config.cfg )

如何在PowerShell 3.0中实现这一点?我试过使用Foreach对象,但找不到一种方法来分配三个变量

您可以按冒号拆分数据并分配每个元素:

$config = Get-Content config.cfg
$FTP_HOST = ($config -split ":")[0]
$FTP_USER = ($config -split ":")[1]
$FTP_PASS = ($config -split ":")[2]
或将数据预拆分为数组,然后分配数组元素:

$config = Get-Content config.cfg
$carry = $config -split ":"
$FTP_HOST = $carry[0]
#etc...

您可以按冒号拆分数据并分配每个元素:

$config = Get-Content config.cfg
$FTP_HOST = ($config -split ":")[0]
$FTP_USER = ($config -split ":")[1]
$FTP_PASS = ($config -split ":")[2]
或将数据预拆分为数组,然后分配数组元素:

$config = Get-Content config.cfg
$carry = $config -split ":"
$FTP_HOST = $carry[0]
#etc...

您可以按冒号拆分数据并分配每个元素:

$config = Get-Content config.cfg
$FTP_HOST = ($config -split ":")[0]
$FTP_USER = ($config -split ":")[1]
$FTP_PASS = ($config -split ":")[2]
或将数据预拆分为数组,然后分配数组元素:

$config = Get-Content config.cfg
$carry = $config -split ":"
$FTP_HOST = $carry[0]
#etc...

您可以按冒号拆分数据并分配每个元素:

$config = Get-Content config.cfg
$FTP_HOST = ($config -split ":")[0]
$FTP_USER = ($config -split ":")[1]
$FTP_PASS = ($config -split ":")[2]
或将数据预拆分为数组,然后分配数组元素:

$config = Get-Content config.cfg
$carry = $config -split ":"
$FTP_HOST = $carry[0]
#etc...

PowerShell学习了Perl和Python,因此您可以这样做:

$FTP\u HOST、$FTP\u USER、$FTP\u PASS=(获取内容。\config.cfg)-split':'

PowerShell学习了Perl和Python,因此您可以执行以下操作:

$FTP\u HOST、$FTP\u USER、$FTP\u PASS=(获取内容。\config.cfg)-split':'

PowerShell学习了Perl和Python,因此您可以执行以下操作:

$FTP\u HOST、$FTP\u USER、$FTP\u PASS=(获取内容。\config.cfg)-split':'

PowerShell学习了Perl和Python,因此您可以执行以下操作:

$FTP\u HOST、$FTP\u USER、$FTP\u PASS=(获取内容。\config.cfg)-split':'

工作起来又漂亮又流畅。非常感谢。工作起来很顺利。非常感谢。工作起来很顺利。非常感谢。工作起来很顺利。非常感谢。伟大的我更喜欢单线的东西。非常感谢。伟大的我更喜欢单线的东西。非常感谢。伟大的我更喜欢单线的东西。非常感谢。伟大的我更喜欢单线的东西。非常感谢。