- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: script problem
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
Forums
Discussions
Discussions
Discussions
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
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
10-03-2005 12:04 PM
10-03-2005 12:04 PM
grep `date +%a", "%e" "%b" "%G` /home/erd_manager/Inbox |wc -l
I get a positive value back but when using the script bellow I get 0 even though echo $express_var is set. What's wrong with the script?
#!/usr/bin/ksh
express_var=`date +%a", "%e" "%b" "%G`
express_var="Date: "$express_var
echo $express_var
grep '$express_var' /home/erd_manager/Inbox |wc -l
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 12:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 12:14 PM
10-03-2005 12:14 PM
Re: script problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 01:34 PM
10-03-2005 01:34 PM
Re: script problem
Did some playing, on my system this happens.
The output of the command itself looks like this:
$ date +%a", "%e" "%b" "%G
Tue, 4 Oct 2005
The output of putting it into a variable and echo'ing looks like this:
$ var=`date +%a", "%e" "%b" "%G`
$ echo $var
Tue, 4 Oct 2005
Notice how when there is a double space in the actual command output i.e. "Tue, 4 Oct" and in the echo $var output it looks like "Tue, 4 Oct"... there is a space missing.
Confirm this is the same on your system and you might have found the problem... the missing space!
Since you say you can run it manually and get a result I'm going to assume your "Inbox" file has the date like "Tue, 4 Oct" if the date is less than 10. %e to date will add an extra space if the date is less than 10 and this extra space goes missing when placed into a variable... for some unknown reason. I've looked at it for a while and can't for the life of me figure out why... no doubt overlooking something obvious.
If you can't find a way to stop it from doing this script around it... if the date is less than 10 manually insert the space back in or something.
Also the previous poster is 100% correct, single quotes around the variable won't work in the grep due to them not evaluating the variable but using $express_var as a literal string to search for...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 01:38 PM
10-03-2005 01:38 PM
Re: script problem
The command output should look like this:
$ date "+%a, %e %b %G"
Tue, 4 Oct 2005
My previous post makes it looks like there is only one space... GRRR... even though there is quite clearly two space even in this one the forum post is only showing one in the preview! Something buggy going on.
Which makes it possible that a similar thing happened to you when you were pasting in your commands and I see only one space when you used multiple spaces or something.
Hopefully my reply makes sense... if it doesn't I've attached a text file with what I was trying to show which will, hopefully, not be modified by the forum when I post it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 01:53 PM
10-03-2005 01:53 PM
Re: script problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 06:01 PM
10-03-2005 06:01 PM
Re: script problem
# date +%a", "%e" "%b" "%G
Mon, 3 Oct 2005
# echo "Mon, 3 Oct 2005" | grep '`date +%a", "%e" "%b" "%G`'
Use double quote:
# echo "Mon, 3 Oct 2005" | grep "`date +%a", "%e" "%b" "%G`"
Mon, 3 Oct 2005
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2005 07:32 PM
10-03-2005 07:32 PM
Re: script problem
var=`date +%a", "%e" "%b" "%G`
grep "$var"
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2005 06:54 AM
10-04-2005 06:54 AM
Re: script problem
Thanks everyone.