如何使用if else在linux shell中设置var值

时间:2014-06-19 03:51:33

标签: linux shell

如何使用if-else在linux shell中设置var值?

我是linux的首发。我想在shell中设置条件的var值。怎么做?
下面的代码是php代码;我不知道怎么用linux编写。

#!bin/bash
# how to use if else to set var value in linux shell
if($x==1){
    $y="hello"
}
if($x==2){
    $y="world"
}
if($x==3){
    $y="good"
}

echo $y

1 个答案:

答案 0 :(得分:2)

如果是bash中的其他内容 http://www.thegeekstuff.com/2010/06/bash-if-statement-examples/

#!/bin/bash
count=100
if [ $count -eq 100 ]
then
  echo "Count is 100"
fi

在bash中设置var http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-5.html

#!/bin/bash          
            STR="Hello World!"
            echo $STR