Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, If i am using following code my script is working fine: >cat test name=$1 echo "your name is $name" I am getting valid response for this.But if i am ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Posts
    10

    Exclamation Not able to pass parameter in main function of Shell Script

    Hi,

    If i am using following code my script is working fine:

    >cat test
    name=$1
    echo "your name is $name"

    I am getting valid response for this.But if i am using a main function and passing the parameter its not working.

    >cat test
    main()
    {
    name =$1
    echo "your name is $name"
    }
    main

    Output while using this code is as follow:
    >./test hello
    your name is

    Kindly suggest what should I do to make it working.

    Thanks-
    Yogender

  2. #2
    Just Joined!
    Join Date
    Nov 2007
    Posts
    10
    Hi All,

    Now I got it and i am able to make it working.

    Thanks-
    Yogender

  3. #3
    Just Joined! cfajohnson's Avatar
    Join Date
    May 2007
    Location
    Toronto, Canada
    Posts
    52
    Quote Originally Posted by bisla.yogender View Post
    Now I got it and i am able to make it working.
    For the benefit of others with the same problem, it is helpful to post the solution.

    Here it is:
    Code:
    main "$@"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...