if文を下に凝縮しようと考えていますが、基本的にはコードを可能な限り縮小しています。if文の範囲の最適化の考え方
データを取得するためにこれをファイルから取得していますが、これはコードに含まれていますが、そのままでコードを縮小できますか?
`
#! /bin/bash
shopt -s nocasematch extglob
callsign() {
while true; do
read -ep "Insert your call sign: " input
if [[ $input = [aknw]@(|[a-z])[0-9][a-z]@(|[a-z]@(|[a-z])) ]]; then
break
else
echo "please insert valid call sign."
fi
done
clear
CAC
}
function CAC() {
ping -c 1 "www.google.com" &> /dev/null && lynx --dump http://callsign.ualr.edu/cdetail.php?call=$input|grep -ve '^ ' || CallsignDetails
CCyn
}
function CCyn() {
while true; do
read -p "Would you like to Lookup another callsign [y/n]" yn
case $yn in
[Yy]*) Last;;
[Nn]*) exit;;
*) echo "please answer yes or no.";;
esac
done
}
function Save() {
cat <<log>> CallSign.log
$(ping -c 1 "www.google.com" &> /dev/null && lynx --dump http://callsign.ualr.edu/cdetail.php?call=$input|grep -ve '^ ' || CallsignDetails)
____________________________________________
log
callsign
}
function Last() {
while true; do
read -p "Would you like to Log The Last callsign [y/n]" yn
case $yn in
[Yy]*) Save;;
[Nn]*) callsign;;
*) echo "please answer yes or no.";;
esac
done
}
function CallsignDetails() {
CsT=$(echo $input | awk '{print toupper($0)}')
clear
LC_ALL=C grep -w $CsT l_amat/HD.dat | tail -1 | awk -F '|' '{print $5}'
echo ""
LC_ALL=C grep -w $CsT l_amat/EN.dat | tail -1 | awk -F '|' '{print $8}'
echo ""
LC_ALL=C grep -w $CsT l_amat/EN.dat | tail -1 | awk -F '|' '{print $16}'
echo ""
echo "$(echo $(LC_ALL=C grep -w $CsT l_amat/EN.dat | tail -1 | awk -F '|' '{print $17}'), $(LC_ALL=C grep -w $CsT l_amat/EN.dat | awk -F '|' '{print $18, $19}'))"
echo ""
echo ""
PClass="$(LC_ALL=C grep -w $CsT -w l_amat/AM.dat | tail -1 | awk -F '|' '{print $17}')"
Class="$(grep -w $CsT l_amat/AM.dat | tail -1 | awk -F '|' '{print $6}')"
if [ "$Class" == "E" ];then
echo "Class: Extra"
else
if [ "$Class" == "G" ];then
echo "Class: General"
else
if [ "$Class" == "A" ];then
echo "Class: Advanced"
else
if [ "$Class" == "P" ];then
echo "Class: Technician Plus"
else
if [ "$Class" == "N" ];then
echo "Class: Novice"
else
if [ "$Class" == "T" ];then
echo "Class: Technician"
else
if [ "$Class" != "T" ];then
echo "Class: Unknown"
fi
fi
fi
fi
fi
fi
fi
if [ "$PClass" == "E" ];then
echo "Previous Class: Extra"
else
if [ "$PClass" == "G" ];then
echo "Previous Class: General"
else
if [ "$PClass" == "A" ];then
echo "Previous Class: Advanced"
else
if [ "$PClass" == "P" ];then
echo "Previous Class: Technician Plus"
else
if [ "$PClass" == "N" ];then
echo "Previous Class: Novice"
else
if [ "$PClass" == "T" ];then
echo "Previous Class: Technician"
else
if [ "$PClass" != "T" ];then
echo "Previous Class: N/a"
fi
fi
fi
fi
fi
fi
echo "Previous Callsigns: $(LC_ALL=C grep -w $CsT l_amat/AM.dat | tail -1 | awk -F '|' '{print $16}')"
LStatus="$(LC_ALL=C grep $CsT -w l_amat/HD.dat | tail -1 | awk -F '|' '{print $6}')"
if [ "$LStatus" == "A" ];then
echo "License status: Active"
else
if [ "$LStatus" == "C" ];then
echo "License status: Canceled"
else
if [ "$LStatus" == "E" ];then
echo "License status: Expired"
fi
fi
fi
echo "Grant date: $(LC_ALL=C grep -w $CsT l_amat/HD.dat | tail -1 | awk -F '|' '{print $8}')"
echo "Expiration date: $(LC_ALL=C grep -w $CsT l_amat/HD.dat | tail -1 | awk -F '|' '{print $9}')"
fi
CCyn
}
callsign`
だから、あなたはすべての可能な値のためにその長いパイプラインを繰り返すことが最適であると思いますか?あなたはそれを一度やってその価値を保存しませんか? – John3136
私はそれが失敗した変数にしようとするたびに、http://codereview.stackexchange.com/ – John3136
に属しているので、この質問をオフトピックとして閉じるように投票しています。どうしようとしましたか?Class = $(LC_ALL = C grep -w $ CsT l_amat/AM.dat | awk -F '|' '{print $ 6}') – Hugo0Boss