2013年1月20日 星期日

[Bash] Put all function into one file


[Bash] Put all function into one file




  1. Create three bash file call A B C

    A :





    #!/bin/bash

    print1()

    {

        echo $1

    }



    print2()

    {

        echo $1

        echo $2

        echo $3

    }



    B:

    #!/bin/bash



    PWD=$(pwd)

    echo $PWD

    source $PWD/A.sh



    b=$1

    print1 $b



    C:

    #!/bin/bash



    PWD=$(pwd)

    echo $PWD

    source $PWD/A.sh





    print2 $1

    print2 $2

    print2 $3

     


  2. Excute B

    The Result

    bash B.sh 'ABCD' 'B' 'D'

    /home/freeman/Desktop/test

    ABCD

     


  3. Excute C

    The Result



    bash C.sh 'ABCD' 'B' 'D'

    /home/freeman/Desktop/test

    ABCD





    B





    D



 



Reference :



Related Posts:

0 意見:

張貼留言