Operating System - HP-UX
1830201 Members
29931 Online
109999 Solutions
New Discussion

Variable assignment in script

 
Stephen Ng
Occasional Advisor

Variable assignment in script

I have the following script:

#!/bin/ksh
d="/p05/oracle/migrate/sng"
a=$d"/source/*.pkh"
echo $a
echo "aa"$a

where /p05/oracle/migrate/sng/source has three files
file1.pkh, file2.pkh, file3.pkh

I expected echo $a to show
/p05/oracle/migrate/sng/source/*.pkh

but it show
/p05/oracle/migrate/sng/source/file1.pkh /p05/oracle/migrate/sng/source/file2.pkh /p05/oracle/migrate/hapay/source/file3.pkh

while $echo "aa"$a show
aa/p05/oracle/migrate/hapay/sng/*pkh
2 REPLIES 2
harry d brown jr
Honored Contributor

Re: Variable assignment in script


Steven,

I'd panic, because I have no clue where the directory
/p05/oracle/migrate/hapay
or how it came into play here. There's nothing in your script-ette that allows for that!

Was that a typo??

is it possible to see some actual output?

live free or die
harry
Live Free or Die
John Poff
Honored Contributor

Re: Variable assignment in script

Hi,

Your ksh script is expanding the '*' between the double quotes in your 'a' variable assignment. You can either escape the '*' like this:

a=${d}"/source/\*.pkh"

or you can turn off globbing in your script with the 'set -f' option.

Here is a quote from the ksh man page that explains a bit about what happens:

"File Name Generation

Following substitution, each command word is processed as a pattern for file name expansion unless the -f option has been set. The form of the patterns is the Pattern Matching Notation defined by regexp(5) . The word is replaced with sorted file names matching the pattern. If no file name is found that matches the pattern, the word is left unchanged."

JP