当前位置: 首页 > news >正文

[bash]:BASH中的变量——可先用后定义

[bash]:BASH中的变量——可先用后定义

 

 

 

 

一、说明

 

 

 

二、脚本

[wit@test:tmp]$ cat  bash_test 
#!/usr/bin/env bashfunction do_msg()
{echols -lh .echoecho -e "\t[DO_MSG]#\tHahaha......"# variables(no position):  first use , last define.echo -e "\t[DO_MSG]#\t${FILE_NAME}"}# function: if FILE exists then DO_SOMETHING.
# function: if $1($1==FILE) exists; then  $2(do-$2)
function test_file_do()
{if [[ -e $1 ]]then$2fi
}FILE_NAME="books.txt"
touch ${FILE_NAME}# if ${FILE_NAME} exists; then do_msg
test_file_do  ${FILE_NAME}  do_msg[wit@test:tmp]$ 

 

 

 

三、参考内容

 

  1、  无

 

  .