- 论坛徽章:
- 0
|
Bash 裡有變量擴展 ${var ffset:length} ${var ffset} 大家都知道,
一般會由右到左, 但其實可由左到右的,看 screenshot
[victor@localhost ~]$ echo ${USER}
victor
[victor@localhost ~]$ echo ${USER:1}
ictor
[victor@localhost ~]$ echo ${USER:5:1}
r
[victor@localhost ~]$ echo ${USER -1)}
r
[victor@localhost ~]$ echo ${USER -2)}
or
[victor@localhost ~]$ echo ${USER -5)}
ictor
[victor@localhost ~]$
但KSH 好像不成....
bash3.X 多了個內建變量, $BASH_ARGV , 那是將命令列上的參數帶入這個變量裏,以數組出現,
${BASH_ARGV[0]} 是命令列參數最後一個,由左到右,看 screenshot
victor@localhost ~]$ cat aa.sh
#! /bin/bash
i=0
for j
do
echo ${BASH_ARGV[$i]}
let "i += 1"
done
[victor@localhost ~]$ sh aa.sh 1 2 3 4 5
5
4
3
2
1
[victor@localhost ~]$
如有錯誤,敬請指正,歡迎交流 ^^ |
|