おれさまラボ

実際に手を動かして理解を深めるブログ。

2018-02-04から1日間の記事一覧

Google Cloud Shell を使ってみる

Google Cloud Shell は Google Cloud Platform に登録すると使える Linux 環境です。Webブラウザ経由でのアクセスなので便利そうです。 Google Cloud Platform(GCP) への登録 登録には住所やクレジットカード番号が必要です。現在12ヶ月間(300ドル)の無料…

Google Chromeを使ってスクリーンショットの取得を自動化する

Google Chromeのインストール Qiita の記事通りに Google Chrome をインストールしてみます。 [root@22a4bea55835 share]# cd /usr/local/src/ [root@22a4bea55835 src]# wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm …

Bash:readlink コマンドで引数で指定したパスの絶対パスを取得する

readlinkというコマンドを見かけたので、メモ。もともとは、シンボリックリンクのリンク先を確認できるコマンドらしい。 構文 readlink -f <ファイルパス> 実行結果 [root@7545c727c36b log]# pwd /var/log [root@7545c727c36b log]# readlink -f . /var/log…

Powershell: Powershellから別のプロセスを起動する

構文 Start-Process -FilePath 'C:\Program Files (x86)\Hidemaru\Hidemaru.exe' -ArgumentList $fullPath -Wait Powershellスクリプトから別のプロセス(今回だと秀丸エディタ)を起動する場合、Start-Processを利用します。 -FilePathを使って実行ファイル…

Powershell: ファイル内の文字列を置き換える

構文 $data = Get-Content ./test_bef.txt -Encoding UTF8 $data = $data | ForEach-Object { $_ -replace "置き換え前の文字列","置き換え後の文字列" } $data | Out-File ./test_aft.txt -Encoding utf8 Get-Content でファイルの内容を読み込みます。 読…

Powershell: ユーザからの入力を受け付ける

構文 Read-Host "Input" Read-Host に続けて、表示したいプロンプトを書くだけでOKです。 実行結果 PS C:\Users\Naoto\Documents\00.lab> Read-Host "Input" Input: test test

Powershell: 現在時刻を取得する

タイムスタンプをファイル名にしたいときなど、現在時刻を取得したいケースは多々あります。 構文 Get-Date -Format "yyyyMMdd-HHmm" 実行結果 PS C:\Users\Naoto\Documents\00.lab> Get-Date -Format "yyyyMMdd-HHmm" 20180204-1032

Powershell: 環境変数を利用する

例えば、%userprofile%を使いたい場合はこう。 $env:UserProfile すべての環境変数を表示したい場合はこうする。 Get-ChildItem env: 参考 環境変数 - Windows管理者のためのPowerShell

Powershell: スクリプト自身が存在するディレクトリを取得する

構文 $PSScriptRoot $PSScriptRootは、スクリプトの親ディレクトリを格納している特殊変数です。 サンプルスクリプト $scriptDir = $PSScriptRoot Write-Host $scriptDir 出力結果 PS C:\Users\Naoto\Documents\00.lab> pwd Path ---- C:\Users\Naoto\Docume…

Powershell: コンソールに文字列を表示する

構文 Write-Host "This is a test message." Write-Hostは、コンソールメッセージを表示させるコマンドです。Linux でいう echo コマンドに該当します。 出力結果 PS C:\Users\Naoto\Documents\00.lab> Write-Host "This is a test message." This is a test…

EZmemo というスクリプトを書きました。

はじめに 使い方 おわりに