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

sourceコマンドに知ったこと~SSHにsourceコマンドは不要~

Posted at

source コマンドとは

  • シェルスクリプトや環境設定ファイルを現在のシェル環境に読み込むコマンド
  • 別名: .(ドット)コマンド
  • 使い方
    source ~/.bashrc
    # または
    . ~/.bashrc
    

.だけで使えるんですね.初めて知りました

どんなときに使うの?

ずばり,.bashrcや.zshrcを変更した時です!
シェル環境を変更したときに,それを適応させるイメージですね

  1. シェルの環境変数を設定する場合

    # 環境変数の設定
    export PATH=$PATH:/new/path
    
  2. シェル関数を定義する場合

    # 関数定義
    function hello() {
        echo "Hello World"
    }
    
  3. エイリアスを設定する場合

    # エイリアス設定
    alias ll='ls -la'
    

SSH設定に source が不要

sourceコマンドは先ほど伝えましたが,シェル環境の変更を読み込むためのコマンドです.
SSHは自動で更新されますし,環境を変えた時点でそれが反映されています.

わたしは,そこを理解していなく,gitのssh設定しているときにsourceコマンドを使って,なんでエラーなるんだ??と焦っていました💦

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