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?

More than 5 years have passed since last update.

ShellScript作るときによく使うやつ

1
Posted at

なんか便利そうなやつ

なんか画面に入力してほしいときのやつ

read -p "なんか入力してちょ: " INPUT_VAL

なんか確認するやつ

function confirmation_to_continue() {
  read -p "よろしいですか? (y/N): " yn
  case "$yn" in [yY]*) ;; *) echo "abort." ; exit ;; esac
}

空判定するやつ

function error_if_empty() {
  while [ -z "$1" ]; do
    echo "入力値が空です。"
    exit 1
  done
}

数値判定するやつ

function error_if_not_numeric() {
  expr "$1" + 1 >/dev/null 2>&1
  while ! [ $? -lt 2 ]; do
    echo "数値で入力してください。"
    exit 1
  done
}

DBでなんやかんややりたいやつ

なんかDBから値とってきたいやつ

VAL=$(echo ${QUERY} | ${MYSQL} -N)

transactionしたくね?的なやつ

${MYSQL} <<EOF
    BEGIN;
    $QUERY
    COMMIT;
EOF
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?