#!/bin/bash
while :
do
echo "Please enter your tittle:"
read TITTLE
echo "Please enter your surname:"
read SURNAME
echo "Please enter your ID No."
read ID
if [ "$TITTLE" = "" ] || [ "${TITTLE//[!0-9]}" != "" ];
then
echo "Enter your valid tittle without special characters."
echo "Please try again."
continue
fi
if [ "$SURNAME" = "" ] || [ "${SURNAME//[!0-9]}" != "" ];
then
echo "Enter your valid surname without special characters."
echo "Please try again."
continue
fi
if [ "$ID" = "" ] || [ "${ID//[0-9]}" != "" ];
then
echo "Enter your valid ID No. without special characters."
echo "Please try again"
else
echo "Thank you" $TITTLE $SURNAME
break
fi
done
ベストアンサー1
仮定:$SURNAME
ユーザー名
$TITTLE
$SURNAME
の内容を、および$ID
の内容と名付けられたファイルに書き込むには、$SURNAME
次のようにコードを修正すればよい。
...
else
echo "Thank you $TITTLE $SURNAME, your information will be stored in \"$SURNAME.txt\""
echo -e "$TITTLE\n$SURNAME\n$ID" > "$SURNAME.txt"
break
...
そのうち -e を使用すると、echo を\n
「改行文字」として認識できます。