0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【DOS】ワンライナーで連続してコマンドを実行する

Posted at

はじめに

Linuxだと以下のようにワンライナーでコマンドを実行することがありますが、同じようなことをコマンドプロンプトでも実現できないかと思い、実装方法を検討してみました。

[nkojima@myhost ~]$ date; md5sum sample.pdf

実装方法

  • Windowsでは、コマンド1 & コマンド2 & コマンド3... という形になります。
    • Linuxだとコマンドの区切り文字(セパレーター)は「;」を使いましたが、コマンドプロンプト上では「&」になるようです。
  • コマンド1の結果に関わらずコマンド2を実行する場合は「&」、コマンド1が成功した場合に限りコマンド2を実行する場合は「&&」を使います。
C:\Users\NKOJIMA>echo %time% & certutil -hashfile D:\ISO\AlmaLinux-8.3-x86_64-dvd.iso MD5
17:27:00.47
MD5 ハッシュ (対象 D:\ISO\AlmaLinux-8.3-x86_64-dvd.iso):
2734fcd999fbe9d7e81d4dae18db6b7b
CertUtil: -hashfile コマンドは正常に完了しました。

感想

  • Linuxとはコマンドの区切り文字が違うだけなので、覚えやすいのではないかと思います。
  • 調べてみた本人が言うのは変ですが、そもそもコマンドプロンプトは使いづらいのでわざわざワンライナーを使わないような気がします。
    • もしワンライナーを使うとしたら、今ならPowerShellだと思います。

参考URL

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?