- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Something wrong with echo?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:14 AM
тАО08-17-2006 04:14 AM
I copied something very similar to this from a script posted on the forums but there seems to be a problem with echo. All the fields are blank. What's wrong?
Here are the lines from the script:
date "+%Y %m %d %H %M %S" | read year month day hour minute second
echo "Year: $year Month: $month Day: $day Hour: $hour Min: $minute Sec: $second"
Here is the output:
Year: Month: Day: Hour: Min: Sec:
If I run the date command this is what I see:
$date "+%Y %m %d %H %M %S"
2006 08 17 12 10 57
$
What can be wrong. I am completely baffled.
Please help,
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:16 AM
тАО08-17-2006 04:16 AM
Re: Something wrong with echo?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:20 AM
тАО08-17-2006 04:20 AM
SolutionWhen you said "I am completely baffled.", did you really mean to say " I am completely bash'led." ?
I suspect that someone has turned you on to the wonderful world of bash. Well, bash guys will tell you it is working perfectly and your variables were set in a sub-process so that when you exit that sub-process the NEW variables are null.
If's it's bash then the answer is pick another shell. On HP-UX, the POSIX shell is rather hard to beat.
- Tags:
- bash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:20 AM
тАО08-17-2006 04:20 AM
Re: Something wrong with echo?
There isn't anythign wrong with the script.
One way to obtain what you describe is to drop the pipe ("|") character.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:22 AM
тАО08-17-2006 04:22 AM
Re: Something wrong with echo?
Nice name.
Run the help for the script. I think you are not using its options correctly.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:32 AM
тАО08-17-2006 04:32 AM
Re: Something wrong with echo?
Wow, you guys are quick! Clay, you are correct. I am using bash because I want to run it on linux and HPUX. If I switch to the Korn shell, it works on HPUX but still fails on linux. I really need to get all of these values at one time so that the seconds are correct as well. If I try to assign the variables one at a time, the seconds and minutes are sometimes wrong. When I saw a shell script reading multiple variables at one time I thought that would fix my problem.
Any ideas on a workaround?
Thanks,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:40 AM
тАО08-17-2006 04:40 AM
Re: Something wrong with echo?
Its out of date but has no obvious problems.
http://www.hpux.ws/caljd.sh
http://www.hpux.ws/caljd.pl
A. Clay if you feel I should update this, let me know.
Its a one line change for the bash shell and all functionality seesms to work. On Linux.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:45 AM
тАО08-17-2006 04:45 AM
Re: Something wrong with echo?
Portability? Well, how about Perl?. This makes one call for the time:
# perl -MPOSIX=strftime -le 'print strftime "Year: %Y Month: %m Day: %d Hour: %H Min: %M Sec: %S",localtime(time)'
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 04:45 AM
тАО08-17-2006 04:45 AM
Re: Something wrong with echo?
DATE=$(date "+%Y %m %d %H %M %S")
YEAR=$(echo ${DATE} | awk '{print $1}')
MONTH=$(echo ${DATE} | awk '{print $2}')
DAY=$(echo ${DATE} | awk '{print $3}')
HOUR=$(echo ${DATE} | awk '{print $4}')
MINUTE=$(echo ${DATE} | awk '{print $5}')
SECOND=$(echo ${DATE} | awk '{print $6}')
echo "Year: $YEAR Month: $MONTH Day: $DAY Hour: $HOUR Min: $MINUTE Sec: $SECOND"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-17-2006 05:11 AM
тАО08-17-2006 05:11 AM
Re: Something wrong with echo?
Patrick's approach will certainly work but here is a workaround that will work in all cases but I don't like it because it creates a temporary file.
TDIR=${TMPDIR:-/var/tmp}
T1=${TDIR}/x${$}_1.tmp
trap 'eval rm -f ${T1}' 0 1 2 15
date "+%Y %m %d %H %M %S" > ${T1}
read year month day hour minute second < ${T1}
echo "Year: ${year} Month: ${month} Day: ${day} Hour: ${hour} Min: ${minute} Sec: ${second}"
Because there is no sub-process, all shells should be happy. Notice that I put {}'s around all of your variables; sometimes they are needed; sometimes not but they never hurt.
As mentioned, Perl is the portable solution and I view it as my portable solution for caljd.sh (ie caljd.pl) although I am not certain where Steven's reference to caljd.sh comes from with respect to this thread.