Shell programming

Shell Basic

1: Variables and Parameters

    1.1: variable substitude:

              name of variable, value of variable; name is a placeholder for value; Referencing the its value is called variable substitude;

       Let us carefully distinguish between thename of a variableand itsvalue. Ifvariable1 is the name of avariable, then$variable1 is       a   reference to itsvalue,the data item it contains.

      Enclosing a referenced value indouble quotes (" ... ") does not interfere with variable substitution.

      Using single quotes (' ... ') causes the variable name to be used literally, and no substitution will take place.

    Note that $variable is actually a simplified form of${variable}

if [ -z "$uninitializedval" ]

then

    echo "unitialized"

fi


1.2. Variable Assignment

     = the assignment operator;

     using "let" to assignment;    let a=12+1

    In  "for" loop to assignment,  for a in 1 2 3 4 do echo $a done


    read value from stdin:

    read a


1.3 Bash Variables Are Untyped

   Bash does not segregateits variables by "type."
   To lighten the burden of keeping track of variable types in a script, Bashdoes permit declaring variables


1.4. Special Variable Types

Local variables

Variables visible only within a code block or function (see also local variables in functions)

Environmental variables

         Variables that affect the behavior of the shell and user interface.

Positional parameters

Arguments passed to the script from the command line[1] :$0, $1, $2,$3 . . .

$0 is the name of the script itself,$1 is the first argument, $2 the second,$3 the third, and so forth. After $9, the arguments must be enclosed in brackets, for example,${10}, ${11}, ${12}.

The special variables $*  and $@ denote all the positional parameters.


The shift command reassigns the positional parameters, in effect shifting them to the left one notch.

$1 <--- $2, $2 <--- $3, $3 <--- $4, etc.

The old $1 disappears, but $0 (the script name) does not change
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值