It is currently Thu, 20 Jan 2022 09:59:32 GMT



 
Author Message
 How can I print an underscore between two variables
Ok, as stated in the subject I'm working KSH.  It's ksh '88 (don't know
if that matters, but I thought I should throw it out).

Basically, in my script I'm trying to do the following:

somefunc () {
   exec 5>/tmp/out.goes.here
   datestamp=$(date +%Y%m%d)
   # there is a variable called prod that changes based upon other
   # criteria in the script, outside this function

   # many other print lines, but this is the one giving grief
   print -u5 "/path/to/file/to/examine/$var_$datestamp"

   unset datestamp
   exec 5>&-

Basically, this function is dynamically building a configuration to be
used by another program.  Now, when the above function is executed, only
the datestamp variable contents are output.  This is because ksh
believes I'm referencing a variable by the name var_.  Rather, I want an
underscore between the contents of the two variables.

I'm tried a few different things.  If I precede the '_' with a '\', the
'\' character is output as well.  Not desireable.  What options do I
have available to fix this?

Thanks,

---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled.  I do not wish my account at HP to
become a spam haven.



 Mon, 11 Sep 2006 23:58:36 GMT   
 How can I print an underscore between two variables

If var is a variable name, then you have to use {} to bracket the
name, since '_' is a valid character in a variable name. You have to
tell the shell not to consider that part of the variable name:

print -u5 "/path/to/file/to/examine/${var}_$datestamp"

Joe
--
The Dutchman still wears wooden shoes, his cap and coat are patched
with the love that Magaret sewed there...
  - Steve Goodman



 Tue, 12 Sep 2006 00:21:30 GMT   
 How can I print an underscore between two variables

${var}_${datestamp}

--
William Park, Open Geometry Consulting, <opengeome...@yahoo.ca>
Linux solution for data processing and document management.



 Tue, 12 Sep 2006 02:43:51 GMT   
 How can I print an underscore between two variables

Thanks both to Joe and William.  I knew it was simple, but it was
kicking my butt.

--

---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled.  I do not wish my account at HP to
become a spam haven.



 Tue, 12 Sep 2006 03:57:35 GMT   
 How can I print an underscore between two variables
...

Which two variables do you want separated by an underscore?  The data
variable is the only one defined in your function.

Mark



 Tue, 12 Sep 2006 04:27:33 GMT   
 How can I print an underscore between two variables

Try to replace
    print -u5 "/path/to/file/to/examine/$var_$datestamp"
with
    print -u5 "/path/to/file/to/examine/${var}_$datestamp"
or
    print -u5 "/path/to/file/to/examine/${var}_${datestamp}"

so that the '_' is taken literally and not interpreted as part of
a variable name.

Greetings - Gerhard.



 Tue, 12 Sep 2006 06:35:22 GMT   
 
   [ 6 post ] 

Similar Threads

1. f2c: two trailing underscores ????

2. Q: Two-sided, two-pass printing to laserjet

3. Printing to two printers from one queue (Printers print identically not load balancing)

4. PPPD or Tin Cans: Which is Better?

5. Any Canned Class code?

6. It's not bad canned meat...

7. Canned "ping"

8. CGI: apache canned response

9. Canned Proxy URLs to Filter

10. For those of you tired of canned distributions...


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software