0
0

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 1 year has passed since last update.

シェルスクリプト(ファイルに値を追記)

Posted at

はじめに

指定したファイル(file_name)が存在する場合、入力値(input_val)を追加していくシェルスクリプトになります。

実装

sh.sample.sh
# ディレクトリのファイル一覧を表示
ls

# 2回値を標準入力で受け付けて、変数に設定する。
read -p "ファイル名を入力してください:" file_name
read -p "ファイルに追記する値を入力してください:" input_val

# file_nameのファイルが存在する場合は、input_valの値を追記する
if [ -f $file_name ];
then
  # echoの後はセミコロンが必要
  echo $input_val >> $file_name;
else
  echo "ファイルが存在しません"
fi

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?