substitute variable

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
Richard [ Mi, 30 Januar 2008 16:57 ] [ ID #1919738 ]

Re: substitute variable

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.
Ed Morton [ Mi, 30 Januar 2008 17:08 ] [ ID #1919739 ]

Re: substitute variable

On 2008-01-30, Richard <RichardVerzijl [at] gmail.com> 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.
Bill Marcum [ Mi, 30 Januar 2008 17:12 ] [ ID #1919740 ]

Re: substitute variable

In article <slrnfq18g1.70e.marcumbill [at] lark.localnet>,
Bill Marcum <marcumbill [at] bellsouth.net> wrote:

> On 2008-01-30, Richard <RichardVerzijl [at] gmail.com> 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 [at] 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 ***
Barry Margolin [ Do, 31 Januar 2008 07:49 ] [ ID #1920583 ]

Re: substitute variable

On Jan 31, 7:49 am, Barry Margolin <bar... [at] alum.mit.edu> wrote:
> In article <slrnfq18g1.70e.marcumb... [at] lark.localnet>,
> Bill Marcum <marcumb... [at] bellsouth.net> wrote:
>
>
>
> > On 2008-01-30, Richard <RichardVerz... [at] gmail.com> 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... [at] 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
Richard [ Do, 31 Januar 2008 08:42 ] [ ID #1920585 ]

Re: substitute variable

On Jan 31, 7:49 am, Barry Margolin <bar... [at] alum.mit.edu> wrote:
> In article <slrnfq18g1.70e.marcumb... [at] lark.localnet>,
> Bill Marcum <marcumb... [at] bellsouth.net> wrote:
>
>
>
> > On 2008-01-30, Richard <RichardVerz... [at] gmail.com> 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... [at] 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
Richard [ Do, 31 Januar 2008 08:52 ] [ ID #1920586 ]

Re: substitute variable

On Jan 31, 7:49 am, Barry Margolin <bar... [at] alum.mit.edu> wrote:
> In article <slrnfq18g1.70e.marcumb... [at] lark.localnet>,
> Bill Marcum <marcumb... [at] bellsouth.net> wrote:
>
>
>
> > On 2008-01-30, Richard <RichardVerz... [at] gmail.com> 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... [at] 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
Richard [ Do, 31 Januar 2008 09:19 ] [ ID #1920587 ]

Re: substitute variable

On Jan 31, 7:49 am, Barry Margolin <bar... [at] alum.mit.edu> wrote:
> In article <slrnfq18g1.70e.marcumb... [at] lark.localnet>,
> Bill Marcum <marcumb... [at] bellsouth.net> wrote:
>
>
>
> > On 2008-01-30, Richard <RichardVerz... [at] gmail.com> 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... [at] 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
Richard [ Do, 31 Januar 2008 09:49 ] [ ID #1920588 ]

Re: substitute variable

In article
<6d82f2bc-bc88-4750-9cd7-b9324c552047 [at] s12g2000prg.googlegroups.com>,
Richard <RichardVerzijl [at] gmail.com> 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 [at] 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 ***
Barry Margolin [ Fr, 01 Februar 2008 02:23 ] [ ID #1921489 ]
Linux » comp.unix.shell » substitute variable

Vorheriges Thema: Read from a file and then use command 'set'
Nächstes Thema: Script doubt