What are the special dollar sign shell variables?

前端 未结 4 820
北海茫月
北海茫月 2020-11-22 00:44

In Bash, there appear to be several variables which hold special, consistently-meaning values. For instance,

./myprogram &; echo $!

wil

4条回答
  •  隐瞒了意图╮
    2020-11-22 01:24

    To help understand what do $#, $0 and $1, ..., $n do, I use this script:

    #!/bin/bash
    
    for ((i=0; i<=$#; i++)); do
      echo "parameter $i --> ${!i}"
    done
    

    Running it returns a representative output:

    $ ./myparams.sh "hello" "how are you" "i am fine"
    parameter 0 --> myparams.sh
    parameter 1 --> hello
    parameter 2 --> how are you
    parameter 3 --> i am fine
    

提交回复
热议问题