【问题标题】:What is the problem with my bash script and why isn't it working?我的 bash 脚本有什么问题,为什么它不起作用?
【发布时间】:2021-06-16 19:25:38
【问题描述】:
#! bin/bash
echo "Hello what is your first name."
   read name
if [ $name ]; then
   echo "$name, that's a funny name"
else
   echo "I asked for your name, you better answer me, i'll give you another chance, this time you better answer me, you understand, YES or NO"
read response 
   if [ $response ]; then
echo "Then tell me WHAT IS YOUR NAME"
   read name
echo "Finally, thank you, bye $name"
   else 
echo "Say goodbye to your family"
   fi

【问题讨论】:

  • 尝试正确缩进你的代码。
  • 我错过了第二个fi
  • 为了帮助调试 shell 脚本,请使用shellcheck.net
  • 在询问问题时,您需要描述问题所在。什么时候出现问题?它做什么/不做什么,这与你想要的有什么不同?您是否收到任何错误消息(如果有,请报告确切错误消息)。请参阅how to ask a good question 上的帮助条目。
  • 你想用if [ $name ]实现什么?

标签: bash bin


【解决方案1】:

问题似乎出在你的第一线

改变

#! bin/bash

#!/bin/bash

【讨论】:

  • 这没什么区别。
  • @Cyrus 空白没有区别,但 bin/bash/bin/bash (就像这里的情况一样)确实有区别。
  • @BenjaminW.:很好看。那是我逃脱了。
猜你喜欢
  • 2020-07-04
  • 2021-04-20
  • 2020-08-01
  • 1970-01-01
  • 2020-11-04
  • 2013-12-08
  • 1970-01-01
  • 2012-10-07
相关资源
最近更新 更多