1
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?

【備忘録】Linuxコマンドの復習~echoコマンド~

Posted at

はじめに

自分が忘れてしまいがちなLinuxコマンドの復習です。
今回はechoコマンドについて整理します。

echoコマンド

1. ターミナルに文字を出力する

➜  ~ echo 'hello!'
hello!

2. 変数の中身を出力する

➜  ~ a="test"
➜  ~ b="test2"
➜  ~ echo "これは" "$a" "です"
これは test です
➜  ~ echo "こっちは" "$b" "です"
こっちは test2 です

3. ファイルの中に書き込む

# テキストを書き込む
➜  ~ echo "test" > ~/test.txt
➜  ~ cat ~/test.txt
test

# テキストを追記する
➜  ~ echo "test2" >> ~/test.txt
➜  ~ cat ~/test.txt
test
test2

※ファイル(test.txt)がなくても、同時に作成される

4. 注意点

# すでにファイル内にテキストがある場合に'>'を使うと上書きされてしまう
➜  ~ echo "aaa" > ~/test.txt
➜  ~ cat ~/test.txt
aaa

おわりに

普段の学習ではあまり使う機会はありませんが、デプロイ時に使うことが多いと思うのでこれを機に理解しておきたいと思います。

1
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
1
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?