LoginSignup
30
23

More than 3 years have passed since last update.

2016-01-12 Powershell > スクリプトを複数ファイルで実装する方法 > .(ドット)で別スクリプトを読込む

Last updated at Posted at 2016-01-12
動作環境
Windows 8.1 pro (64bit)

Powershellのコードを実装するとき、1つのスクリプトファイルで実装すると見通しが悪い。

将来的には複数のスクリプトファイルに分割して実装を考えているが、そういうことができるのかどうか。

Cのincludeやpythonのimportのような機能があるか、調査中。

.(ドット)を用いた読込み

. "c:\fso\include.ps1"というやり方があるようだ。

コード

以下で実装できた

funcTest1.ps1
function helloTo ($name) {
    echo "hello $name"
}
funcMain.ps1
. ".\\funcTest1.ps1"

helloTo("Hanako")
結果
hello Hanako
30
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
23