Skip to content

シェルスクリプト(LPIC)

   

シェルスクリプト

シェル上で実行できるプログラミング言語です。

変数

$$

シェルのPID

$?

最後に時効したコマンドの終了値

$#

引数の数

関数

$ function snorlaxFunc() { echo 'Snorlax' }
$ snorlaxFunc()
Snorlax

サンプル

snorlax.txtがあるか調べる

if [ -f ./snorlax.txt ]; then
    echo 'snorlax.txt is exists!'
fi
if test -f ./snorlax.txt; then
    echo 'snorlax.txt is exists!'
fi

引数の数を表示する

#!/bin/sh

echo $#
./script.sh snorlax ditto
2

30秒ごとにSnorlaxと出力する

while true
do
  echo Snorlax
  sleep 30
done

関連記事

  1. シェル変数(LPIC)
  2. unalias(LPIC)
  3. alias(LPIC)
  4. SSHキーを設定する(LPIC)
  5. profile、.bash_profile、.profile、.bash_login(LPIC)
  6. rpm2cpio(LPIC)
  7. yum,etc(LPIC)