Topic
2 replies Latest Post - ‏2005-02-07T11:59:51Z by SystemAdmin
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic bash problem

‏2005-01-26T12:17:24Z |
I am working though Daniel Robbins bash by example series and have a problem with Part 2

at the command line I type:

myvar=3
echo $mvar

which, as expected, returns:

3

However when i create a file called myscript.sh containing the following:

#!/usr/bin/env bash

echo $myvar

I get nothing.

I am using Suse 9.2 and have also tried the same on an 8.2 box.

What am I doing wrong?
Updated on 2005-02-07T11:59:51Z at 2005-02-07T11:59:51Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    232 Posts
    ACCEPTED ANSWER

    Re: bash problem

    ‏2005-01-27T14:16:23Z  in response to SystemAdmin
    When you run the shell script, it starts a new instance of bash, and does not pick up on the "myvar" which is only valid in the current shell session. Try:

    myvar=3
    export myvar
    ./myscript.sh
    The export should allow the shell script to pick up the variable.