0
2

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 1 year has passed since last update.

Macでcommandファイル(Windowsのバッチファイルのようなもの)の第一歩

Last updated at Posted at 2022-08-11

概要

MacでWindowsのbatファイルみたいなの作りたいけど…
そもそもどんな拡張子のファイルを作ったらいいか
そのレベルで分からない or 忘れた…な状態向け。

やり方

ターミナルを開いて下記コマンド。

commandファイル作成
touch test.command

下記の場所にファイルが作成される。
(以降の内容はこの場所からtest.commandを移動しなかった前提です)
image.png

作ったcommandファイルをテキストエディットで開く。
image.png

↓中身をこうする。
(今回はtesterという名前のフォルダーを作るだけの簡単な処理)

test.commandの中身
#!/bin/bash

mkdir tester

保存後、test.commandファイルをダブルクリックしても
適切なアクセス権限がないために実行できません。
と弾かれる。
image.png

そこで、ターミナルで下記コマンド実行。

test.commandに実行権限を与えてあげる
chmod u+x test.command

chmod = アクセス権操作コマンド
u = ユーザーに対して
+ = 与える
x = 実行権限を

改めてtest.commandファイルをダブルクリックする。
すると、test.commandと同じフォルダーに『tester』という名前のフォルダーが作成される。

image.png

参考サイトさん

バージョン

macOS Monterey 12.4

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?