星期一, 7月 06, 2009

bash shell script 的 function 與 here-document

* bash shell script 的 function 與 here-document

* 注意: Here-Document 前面不可以有 white-spaces 否則會失效。
* 結論: 不好用,還不如直接定義變數在 function 裡使用。

[code]
#!/bin/bash
# here-function.sh
GetPersonalData ()
{
  read firstname
  read lastname
  read address
  read city
  read state
  read zipcode
} # This certainly looks like an interactive function, but...
# Supply input to the above function.

GetPersonalData <<RECORD001
Bozo
Bozeman
2726 Nondescript Dr.
Baltimore
MD
21226
RECORD001

echo
echo "$firstname $lastname"
echo "$address"
echo "$city, $state $zipcode"
echo
exit 0
[/code]

沒有留言: