你能帮我写这个脚本吗?我正在学习如何在 bash 中创建脚本。它应该可以工作,但不知怎的却没有。
#!/bin/bash
echo "Please enter your name: "
read name
if ["$name"="Marek"]
then
echo -e "Hello Marek!\n"
else
echo "Sorry not you"
fi
输出:
mhudak@nelke:~/practice_before_Exam> ./script2.sh
Please enter your name:
Marek
./script2.sh: line 4: [Marek=Marek]: command not found
Sorry not you
SUSE Linux Enterprise Server 11 (i586)
VERSION = 11
PATCHLEVEL = 1
答案1
尝试这个:
#!/bin/bash
echo "Please enter your name: "
read name
if [ "$name" = "Marek" ]; then
echo -e "Hello Marek!\n"
else
echo "Sorry not you"
fi