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

[Linux]bashコマンドについてメモ

Posted at

bashコマンド

コマンドを並べた命令をパイプから受け取って実行

使用例

$ echo 'print "mkdir test" | bash
$ ls
test   //testというディレクトリができている

ファイルにコマンドを入れて実行もできる

$ echo "mkdir test1" > a   //ファイルaの中に「echo "mkdir test1"」と書き込む
$ ls
a

$ bash ./a   //aファイルを実行
$ ls
a  test1    //test1というディレクトリができている

$ cat a
mkdir test1

このときのファイルaをシェルスクリプトと呼ぶ(shellにやってもらいたいことを書いたファイルのこと)

ファイルだけ実行して同じようにコマンドを発動させる

#!/bin/bash

mkdir test1
mkdir test2

と書いたファイルaを準備してaを実行するのだが、
今のままだとおそらくファイルaに実行権限がついていないのでchmodコマンドで実行権限を付ける

$ chmod +x a
$ ls -l
-rwxrwxr-x 1 misuzz misuzz 37  3月 11 08:22 a    //xが追加された

aファイルの実行

$ ./a
$ ls
a  test1  test2  //test1, test2というディレクトリができてる

#!/bin/bashとは

  • シバンと言う
  • #! スクリプト言語のコマンドの絶対パス
  • シバンを書くと、OSが絶対パスにあるコマンドを呼んで、2行目以降に書かれているコマンドを実行する

見てる本

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?