このスクリプトがあります。
#!/bin/bash
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null 2>&1 && pwd )"
USER_DEF=$(whoami)
function private {
read -p "Enter private chat name: " name
if [[ $name == '' ]] ; then
:
else
if [ -d "$BASE_DIR/chats/private/$name/" ] ; then
pass=$(cat "$BASE_DIR/chats/private/$name/pass")
read -s -p "Enter private chat password: " password
if [[ $password == $pass ]] ; then
chat "private" "$name"
count=$(find $BASE_DIR/chats/private/$name/ -type p)
if [[ "$count" == '' ]] ; then
rm -rf "$BASE_DIR/chats/private/$name"
fi
echo You exited private chat: $name
else
echo Wrong password
fi
fi
fi
unset $options
if [[ -e ./chats/public ]] ; then
options=($(find $BASE_DIR/chats/public -mindepth 1 -type d -printf '%f\n'))
fi
options+=("Enter private room")
options+=("Create public room")
options+=("Create private room")
options+=("Quit")
}
clear
read -r -p "Enter your name [$USER_DEF]: " UD
if [[ $UD = "" ]] ; then
USERNAME=$USER_DEF
else
USERNAME=$UD
fi
clear
echo Welcome back $USERNAME
echo We have this chat in public:
PS3='Please enter your choice: '
if [[ -e ./chats/public ]] ; then
options=($(find $BASE_DIR/chats/public -mindepth 1 -type d -printf '%f\n'))
fi
options+=("Enter private room")
options+=("Create public room")
options+=("Create private room")
options+=("Quit")
while true
do
int_count=1
for el in "${options[@]}"; do
echo "$int_count) $el"
int_count=$(expr $int_count + 1)
done
read -p "$PS3" optional
opt=${options[$(expr $optional - 1)]}
case $opt in
"Enter private room")
private # this is line 150
;;
"Create public room")
create_public
;;
"Create private room")
create_private
;;
"Quit")
echo "Bye, $USERNAME"
exit 0
;;
[a-zA-Z][a-zA-Z0-9]*)
public $opt
;;
esac
done
問題は次のとおりです。メニューを押すとこのエラーが再び1
発生します。Enter
1
script.sh: line 150: private: command not found
それはどういう意味ですか? 1回以上使用できませんか?
答え1
問題はラインです
unset $options
評価時には$options
何よりも単語が含まれているため、シェルはprivate
機能を定義しません。
正しい構文は次のとおりです。
unset options