![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how can i read text file and assign its values to variables using shell | rosalinda | Shell Programming and Scripting | 4 | 08-26-2008 06:20 AM |
| How to store the values in a file into an array | risshanth | UNIX for Dummies Questions & Answers | 3 | 01-22-2008 10:34 AM |
| Read the entire output fired by ps command | vinithepoo | UNIX for Advanced & Expert Users | 5 | 01-19-2008 09:24 AM |
| read values from ps -ef into variables in ksh? | JamesByars | Shell Programming and Scripting | 8 | 01-13-2008 08:12 AM |
| store output to a file and read from it | afadaghi | Shell Programming and Scripting | 2 | 10-04-2005 01:00 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
trouble using read to store values in variables from command output
I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie.
I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me. gist, trying to use output from command: $ date -u '+%d %h %y' <enter> 05 Jan 09 ##want to store 05 Jan 09 to variables DAY MONTH YEAR respectively; also want Jan to be all caps, so tr is used in pipeline## $ date -u '+%d %h %y' | tr '[:lower:]' '[:upper:]' <enter> 05 JAN 09 ##okay, so I got desired format for output, now I want those values stored, so just add a read command statement with the day month year as operands, right??## $ date -u '+%d %h %y' | tr '[:lower:]' '[:upper:]' | read DAY MONTH YEAR <enter> $ echo $DAY $ ##var DAY carries empty value--what am I doing wrong or what would be the correct way to achieve desired result of storing 05 JAN 09 output of date/tr commands to those variables??## thanks in advance |
|
||||
|
update!
by the way, it is a known caveat that you can't use read in a pipeline, because of the way read is called in a subshell. Effectively the values stored to the named variables in read will only be stored in the subshell and not the parent.
I realized why it worked for you. Apparently the $-prompt for bourne and korn shell is the same. I was attempting to do the aforementioned in bourne and I suspected because of what I stated about the parent-child relationship of read when called in a shell, that possibly you were using a shell which compensated for this deficiency. suspected bash at first but obviously korn. Will try to work it out from here, but thanks for your feedback anyway, bobby. I hope this helps others. |
![]() |
| Bookmarks |
| Tags |
| read command pipe variable can't |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|