Copyright(c) by Galaxy CD – http://www.galaxycd.com
40
Baøi 9: Cô cheá thay theá cuûa Shell
Noäi dung: caùch thao taùc vôùi caùc tham soá cuûa shell_script, caùc bieán trong Shell, caùc kyù
töï ñaëc bieät ñöôïc thoâng dòch khi vieát trong caâu leänh shell.
9.1 Truyeàn tham soá:
9.1.1 Truyeàn tham soá cho moät Shell_script
Moät Shell_script coù theå laøm vieäc vôùi caùc thoâng soá ñöôïc truyeàn qua doøng leänh.
$
proc par1 par2 par3
|
|
|
|
$0 $1 $2 $3
Trong Shell_script ñöôïc goïi (trong tröôøng hôïp naøy laø proc), caùc tham soá ñöôïc theå hieän
baèng:
$0
teân Shell_script
$1
tham soá thöù nhaát
$2
tham soá thöù hai
$n
tham soá thöù n
$#
soá caùc tham soá
$*
taát caû caùc tham soá
$$
PID cuûa shell_script
Thí duï:
$
cat param
echo Name of shell_script: $0
echo First parameter : $1
echo Third parameter : $3
echo Number of parameters: $#
echo List of all the param: $*
$
$
param London Paris New-York Brussels
Name of shell_script: param
First parameter: London
Third parameter: New-York
Number of parameters: 4
List of all the param: London Paris New-York Brussels
9.1.2 Dòch chuyeån caùc tham soá: