Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

ShellScriptを作ろう

Posted at

メッセージの表示

echo "Hello, World!"

文字の入力受付

//入力した値を変数に代入する
read ○○
//numという変数に入力した値が代入される
read num

Swich文(Case文)

echo "Enter a number (1-3):"
read num

case $num in
  1)
    echo "You entered One."
    //コマンドの終了を表す「;;」
    ;;
  2)
    echo "You entered Two."
    ;;
  3)
    echo "You entered Three."
    ;;
  *)
    echo "Invalid input."
    ;;
//case文を逆にして終了を表す
esac

関数

function function_name {
  # 関数の本体(コードブロック)
  # 処理内容
}
function_name {
  # function部分は省略できる
}

引数

function greet {
  echo "Hello, $1!"
}

# 関数の呼び出し
greet "John"

if文

if [[ $file_list == *"$target_file"* ]]; then
  echo "あった!"
else
  echo "なかった…"
fi

$( )構文:

バッククオート(``)や$( )で囲まれた部分は、コマンドを実行し、その結果を文字列として取得するためのサブシェル(サブプロセス)として扱われます。

・文字を表示する
・数字の入力を受け付ける
・関数を作成する

1ディレクトリを作成する
2記憶媒体からソフトをインストールする
3インストールされたソフトをディレクトリに入れる
4Shellを叩く

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?