Engineer of the lawyer

I was able to pass the Network Specialist. Next target is the Project Manager.

readを使った簡単なシェルスクリプト

readコマンドとはシェルスクリプト内で標準入力からの入力を受け付ける際に利用できる

(例)ユーザ名を入れると挨拶を返す

[root@lpicprac ~]# cat readtest.sh
echo -n "Who are you? : "
read username
echo "Hello, $username!"
[root@lpicprac ~]# source readtest.sh
Who are you? : hogehoge
Hello, hogehoge!
[root@lpicprac ~]#

ログイン時に自動実行されるように仕込んでみる

[root@lpicprac ~]# cat .bash_profile
#readtest.shの実行
if test -f readtest.sh
        then
                source readtest.sh
        else
                echo '"no readtest.sh"'
fi

rootにログインしてみたところ、うまく動きました。

ログイン時に自動実行されるファイルはいくつかありますが、まとめる機会があればそのうちまとめようと思います。
今回は ~/.bash_profile を使いました。設定したユーザのホームディレクトリにあるファイルを触るので他のユーザには影響ありません。