Rahul sawant
Rahul sawant

Reputation: 425

Calling an attribute in a function into another function in UNIX

Below is a code snippet

    function currmonth
    {
    curr_mon=`echo $(date +%x)`
    yy=`echo $curr_mon| awk '{print substr($0,9,2)}'`
    mm=`echo $curr_mon| awk '{print substr($0,1,2)}'`
    dd=`echo $(date -d "$mm/1 + 1 month - 1 day" "+%d")`   # <--
    }
    function test
    {
     echo $(currmonth.dd)                                  # <--
    }

I want to call the attribute "dd" which is in function "currmonth" to the function test I tried using the .'DOT' operator to echo it but doesnt help,can u assist me with this

Upvotes: 0

Views: 56

Answers (1)

John Kugelman
John Kugelman

Reputation: 361976

dd is a variable. You can print its value with:

function test
{
    echo $dd
}

currmonth    # call currmonth()
test         # call test()

Upvotes: 1

Related Questions