Results 1 to 4 of 4

Thread: Batch Variables

  1. #1
    Join Date
    Feb 2010
    Location
    The Land of 11,842 Lakes
    Beans
    75

    Batch Variables

    Hello World!

    This may sound a little bit weird because I'm an Ubuntu enthusiast currently using Windows XP, but I'm making a batch file that finds a drive, and then (this is where I'm stumped) in another batch file, I want to use that set variable.
    My instincts are telling me just to use that same variable and try to not set it over in another file, but I think (like always) there's a chance that that's wrong.

    Thanks for any assisstance.
    For a full signature / about me, see my website.

  2. #2
    Join Date
    Jul 2007
    Location
    The Internet
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Batch Variables

    The variable will carry over if you invoke the second script using "source", otherwise if you simply execute it it won't - you'd need to instead pass the variable value as an argument.

    a.sh:

    Code:
    #!/bin/bash
    
    myvar="blah blah"
    source ./b.sh
    b.sh:

    Code:
    #!/bin/bash
    
    echo "myvar = $myvar"
    (make both files executable)

    Result:
    > ./a.sh
    myvar = blah blah


    But when a.sh is:

    Code:
    #!/bin/bash
    
    myvar="blah blah"
    ./b.sh
    we get:

    > ./a.sh
    myvar =

  3. #3
    Join Date
    Apr 2008
    Location
    RiceMonsterland, Canada
    Beans
    Hidden!

    Re: Batch Variables

    Quote Originally Posted by Sporkman View Post
    *snip*
    Batch, not bash.
    Code:
    while true; do echo -n "RiceMonster "; done
    Best thread ever

  4. #4
    Join Date
    Jul 2007
    Location
    The Internet
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Batch Variables

    Quote Originally Posted by RiceMonster View Post
    Batch, not bash.
    D'Oh!!

    This gross misinterpretation on my part needs some Freudian analysis. Any interested parties, please proceed...

Tags for this Thread

Bookmarks

Posting Permissions

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