substitute variable
am 30.01.2008 16:57:55 von Richard
Hi,
I want to substitute a variable. My script code is
#!/bin/sh
MYDIR="/usr/"
echo "${MYDIR}file.cpp"
What I want to see after running the script (ksh) is /usr/file.cpp but
what I see is only file.cpp.
I think there is some strange substitution taking place.
Does anyone know what goes wrong?
Regards,
Richard
Re: substitute variable
am 30.01.2008 17:08:35 von Ed Morton
On 1/30/2008 9:57 AM, Richard wrote:
> Hi,
>
> I want to substitute a variable. My script code is
>
> #!/bin/sh
> MYDIR="/usr/"
> echo "${MYDIR}file.cpp"
>
> What I want to see after running the script (ksh)
Why did you say "(ksh)" when your shebang says "/bin/sh"?
> is /usr/file.cpp but
> what I see is only file.cpp.
That's hard to believe. Assuming your script is in a file named "foo" under your
current directory, do this:
$ cat foo
$ ./foo
and post the result.
Ed.
Re: substitute variable
am 30.01.2008 17:12:49 von Bill Marcum
On 2008-01-30, Richard wrote:
>
>
> Hi,
>
> I want to substitute a variable. My script code is
>
> #!/bin/sh
> MYDIR="/usr/"
> echo "${MYDIR}file.cpp"
>
> What I want to see after running the script (ksh) is /usr/file.cpp but
> what I see is only file.cpp.
> I think there is some strange substitution taking place.
> Does anyone know what goes wrong?
>
The script runs in a subshell unless you execute it using the "."
command.
Re: substitute variable
am 31.01.2008 07:49:53 von Barry Margolin
In article ,
Bill Marcum wrote:
> On 2008-01-30, Richard wrote:
> >
> >
> > Hi,
> >
> > I want to substitute a variable. My script code is
> >
> > #!/bin/sh
> > MYDIR="/usr/"
> > echo "${MYDIR}file.cpp"
> >
> > What I want to see after running the script (ksh) is /usr/file.cpp but
> > what I see is only file.cpp.
> > I think there is some strange substitution taking place.
> > Does anyone know what goes wrong?
> >
> The script runs in a subshell unless you execute it using the "."
> command.
Why should that matter? The echo command is in the script, not being
executed after the script finishes.
I suspect a typo in the original script.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Re: substitute variable
am 31.01.2008 08:42:34 von Richard
On Jan 31, 7:49 am, Barry Margolin wrote:
> In article ,
> Bill Marcum wrote:
>
>
>
> > On 2008-01-30, Richard wrote:
>
> > > Hi,
>
> > > I want to substitute a variable. My script code is
>
> > > #!/bin/sh
> > > MYDIR="/usr/"
> > > echo "${MYDIR}file.cpp"
>
> > > What I want to see after running the script (ksh) is /usr/file.cpp but
> > > what I see is only file.cpp.
> > > I think there is some strange substitution taking place.
> > > Does anyone know what goes wrong?
>
> > The script runs in a subshell unless you execute it using the "."
> > command.
>
> Why should that matter? The echo command is in the script, not being
> executed after the script finishes.
>
> I suspect a typo in the original script.
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
I figured it out. The script was in DOS mode (CR + LF) in stead of
Unix mode (LF). I created it with the editor PSPad via FTP.
Thanks for your help,
Richard
Re: substitute variable
am 31.01.2008 08:52:28 von Richard
On Jan 31, 7:49 am, Barry Margolin wrote:
> In article ,
> Bill Marcum wrote:
>
>
>
> > On 2008-01-30, Richard wrote:
>
> > > Hi,
>
> > > I want to substitute a variable. My script code is
>
> > > #!/bin/sh
> > > MYDIR="/usr/"
> > > echo "${MYDIR}file.cpp"
>
> > > What I want to see after running the script (ksh) is /usr/file.cpp but
> > > what I see is only file.cpp.
> > > I think there is some strange substitution taking place.
> > > Does anyone know what goes wrong?
>
> > The script runs in a subshell unless you execute it using the "."
> > command.
>
> Why should that matter? The echo command is in the script, not being
> executed after the script finishes.
>
> I suspect a typo in the original script.
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
I figured it out. The script was in DOS mode (CR + LF) in stead of
Unix mode (LF). I created it with the editor PSPad via FTP.
Thanks for your help,
Richard
Re: substitute variable
am 31.01.2008 09:19:26 von Richard
On Jan 31, 7:49 am, Barry Margolin wrote:
> In article ,
> Bill Marcum wrote:
>
>
>
> > On 2008-01-30, Richard wrote:
>
> > > Hi,
>
> > > I want to substitute a variable. My script code is
>
> > > #!/bin/sh
> > > MYDIR="/usr/"
> > > echo "${MYDIR}file.cpp"
>
> > > What I want to see after running the script (ksh) is /usr/file.cpp but
> > > what I see is only file.cpp.
> > > I think there is some strange substitution taking place.
> > > Does anyone know what goes wrong?
>
> > The script runs in a subshell unless you execute it using the "."
> > command.
>
> Why should that matter? The echo command is in the script, not being
> executed after the script finishes.
>
> I suspect a typo in the original script.
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
I figured it out. The script was in DOS mode (CR + LF) in stead of
Unix mode (LF). I created it with the editor PSPad via FTP.
Thanks for your help,
Richard
Re: substitute variable
am 31.01.2008 09:49:44 von Richard
On Jan 31, 7:49 am, Barry Margolin wrote:
> In article ,
> Bill Marcum wrote:
>
>
>
> > On 2008-01-30, Richard wrote:
>
> > > Hi,
>
> > > I want to substitute a variable. My script code is
>
> > > #!/bin/sh
> > > MYDIR="/usr/"
> > > echo "${MYDIR}file.cpp"
>
> > > What I want to see after running the script (ksh) is /usr/file.cpp but
> > > what I see is only file.cpp.
> > > I think there is some strange substitution taking place.
> > > Does anyone know what goes wrong?
>
> > The script runs in a subshell unless you execute it using the "."
> > command.
>
> Why should that matter? The echo command is in the script, not being
> executed after the script finishes.
>
> I suspect a typo in the original script.
>
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***
> *** PLEASE don't copy me on replies, I'll read them in the group ***
I figured it out. The script was in DOS mode (CR + LF) in stead of
Unix mode (LF). I created it with the editor PSPad via FTP.
Thanks for your help,
Richard
Re: substitute variable
am 01.02.2008 02:23:25 von Barry Margolin
In article
<6d82f2bc-bc88-4750-9cd7-b9324c552047@s12g2000prg.googlegroups.com>,
Richard wrote:
> I figured it out. The script was in DOS mode (CR + LF) in stead of
> Unix mode (LF). I created it with the editor PSPad via FTP.
>
> Thanks for your help,
Good. Next mystery: why did you have to post this reply 4 times?
Actually, it's not much of a mystery: you're using Google Groups. It
probably told you that there was a posting error. It lies.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***