输出保持不变

时间:2016-09-03 12:16:20

标签: linux bash

无论输入如何,输出仍然" Dead,ciao in hell"

ready: function(){
    var leserbriefRef = firebase.database().ref('leserbriefe');
        leserbriefRef.on('value', function(snap) {
          var n = snap.child('numLeserbriefe').val();
          console.log(n);
          this.lbriefe = [];
          for(var i=0; i<n; i++){
                this.push("lbriefe", snap.child('l'+(n - 1 - i)).val());
            }
        });
  }

有人请求帮助我吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

你错过了 $ 符号

echo "Which wire to cut? Red or Green? "
read die
if [[ $die = "red" ]]; then
echo "You are saved!"
else echo "Dead,ciao in hell"
fi

<强>输出

Which wire to cut? Red or Green? 
asd
Dead,ciao in hell
Which wire to cut? Red or Green? 
red
You are saved!

答案 1 :(得分:0)

您应该清理用户输入。说,如果他在恐慌中输入reD怎么办?他还得救了吗?

#!/bin/bash
read -p  "Which wire to cut? Red or Green?" die
die="${die:-GREEN}" # if the die's value is null, set it to GREEN
die="${die^^}" # Convert the input to uppercase
if [ "$die" = "RED" ]
then
  echo "You are saved!"
elif [ "$die" = "GREEN" ]
then
  echo "Dead,ciao in hell"
else
  echo "Confused, you deserve to die"
fi

<强>改进

  • read prompt-p选项
  • 一起使用
  • die添加了空值检查,并使用die="${die:-GREEN}"
  • 将默认值设置为“绿色”
  • 添加了elif-else部分来处理非预期值的输入。
  • 由于输入已预处理,因此使用内置[[..]]替换[..]