Operating System - Linux
1753297 Members
6428 Online
108792 Solutions
New Discussion юеВ

Re: Value interpretation issue

 
SOLVED
Go to solution
Jeff_Traigle
Honored Contributor

Value interpretation issue

A coworker of mine is having problems with this and I'm not grasping what the issue is either. The following command works when executed explicitly:

omnidb -filesystem hostname.domain:/boot 'hostname.domain [/boot]'

However, trying to use variables to handle a loop from a list of these parameters like:

while read SYSNAME
do
omnidb -filesystem ${SYSNAME}
done < /omni/fni/bin/ob_fs_list_tst.txt

omnidb gives a usage synopsis so the value of the variable is not being interpretted in the same way as the explicit command above is even though the command looks the same (and can be copy/pasted to a command line and run successfully). I'm guessing it has something to do with the single quote around the last part of the string that is causing the issue, but we aren't seeing exactly how or how to get around it. Anyone with sharper eyes and brains this morning care to enlighten us?

BTW, each line of the txt file looks like this:

hostname.domain:/ 'hostname.domain [/]'
--
Jeff Traigle
5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: Value interpretation issue

Have you tried escaping the single quotes in the text file?

something like this:

hostname.domain:/ \'hostname.domain [/]\'

or what about quoting your variable

omnidb -filesystem "${SYSNAME}"
Peter Godron
Honored Contributor
Solution

Re: Value interpretation issue

Jeff,
if,as you say, the command is correct and can be cut/pasted, I would re-direct the loop output into a file and then execute the file.

I assume you had tried wrapping the ${SYSNAME} or even -filesystem ... in double quotes?
Jeff_Traigle
Honored Contributor

Re: Value interpretation issue

Yeah. Quoting and escaping in various ways either broke things more or had no effect at all.

Dumping the commands to a separate temporary script as Peter mentioned worked. Not quite as "clean" as we were going for, but, if it works, it works. :)
--
Jeff Traigle
Dennis Handly
Acclaimed Contributor

Re: Value interpretation issue

If this works, you need to remove the quotes in the text file:
omnidb -filesystem hostname.domain:/boot 'hostname.domain [/boot]'

When the shell sees the single quotes, it removes them and passes everything in them as one parm to omnidb.

If omnidb needs them as one parm, you will have to use eval on $SYSNAME to get the quote working the right way?

Doing the read is like
$ X="hhh.ddd:/ 'hhh.ddd [/boot]'"

Trying to pass that to a command and get the quoted string parsed properly is an issue.

$ printenv $X
the count is 4
hhh.ddd:/
'hhh.ddd
[/boot]'

$ printenv "$X"
the count is 2
hhh.ddd:/ 'hhh.ddd [/boot]'

And I assume you want this:
$ printenv hhh.ddd:/ 'hhh.ddd [/boot]'
the count is 3
hhh.ddd:/
hhh.ddd [/boot]

The only solution I see it to rewrite your file like:
hhh.ddd:/|hhh.ddd [/boot]

And change the read to:
$ IFS="|" read PARM1 PARM2

Then $PARM1 and $PARM2 can be passed to omnidb.
Jeff_Traigle
Honored Contributor

Re: Value interpretation issue

I didn't try Dennis' suggestion. The file containing all of the system and directory information is the output from an omnidb command. Don't really care to hack around with that since Peter's suggestion got things working for us.
--
Jeff Traigle