[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

SOLVED: How to use apostrophe in bash shell script?



Kent West wrote:

> nate wrote:
>
> > Kent West said:
> > > I'm trying to use the following in a bash shell script:
> > >
> > > echo This machine's name and IP address
> > > cat /etc/hosts | grep $HOSTNAME
> >
> > try enclosing the line in quotes:
> >
> > echo "This machine's IP address"
> >
> > seems to work for me
> >
> > nate
> >
>
> Thanks for the response.
>
> Both your suggestion and my original line (see above) work from the command
> line, but neither work from the shell script. So, I created a new, minimal shell
> script (below) which does work. So it must be something in my script. I'll take
> a closer look. Thanks for the help!
>
> Contents of script which does work:
> ---------------------
> #!/bin/bash
> echo "This machine's name"
>
> Kent

Thanks to Nate's help, I found the problem. I had another line above this one with
a similar echo'd line that had an apostrophe. Apparently bash was interpreting
everything between the two apostrophe's as a string, which explains some other odd
behaviour I was seeing, but had put on the back burner to deal with this easier
problem first.

Thanks!

Kent




Reply to: