The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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
To call/execute a shell script from a shell script konark UNIX for Dummies Questions & Answers 1 10-26-2007 02:16 PM
How to pass a parameter from one Shell-script to another Shell-script subodhbansal Shell Programming and Scripting 2 09-22-2007 02:19 AM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 05:42 PM
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 1 04-30-2007 05:43 AM
Have a shell script call another shell script and exit heprox Shell Programming and Scripting 2 11-20-2006 05:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-05-2005
Registered User
 

Join Date: Sep 2005
Posts: 10
Help in this shell script

Hi ,
I am trying to do following.
Problem - " Take out today's day from date and then based on day echo some thing. But some how the control is not going in case switch"

Code - here is code

++++++++++++++++++++++++
DAY= date | cut -f 1 -d ' '
echo "$DAY---- is X"

case $DAY in
'Wed')
echo "Today is $DAY - day"
;;
*)
echo "Kya ho raha hai"
;;
esac


+++++++++++++++
So I checked that the cut command is returning me "Wed" with a new line character.
So out put of running above code is

=======
% sh dr.sh
Wed
---- is X
Kya ho raha hai
=======
So you can see extra newline character comin in play !!!!
So can any one help how to truncate all the extra spaces while using cut command ? ANd how can I maeke case run fine here?

thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 10-05-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
This line:
DAY= date | cut -f 1 -d ' '
does not set the variable DAY to anything. It is basicly the same as:
date | cut -f 1 -d ' '

And then the next line just prints an empty $DAY variable.

You want something like:
DAY=`date | cut -f 1 -d ' '`

Next time please tell which shell you are using. Also which version of unix.
Reply With Quote
  #3  
Old 10-05-2005
Registered User
 

Join Date: Sep 2005
Posts: 10
Hi,
I agree I was making a mistake by putting 'space' between + and statement.
But still I am not able to assign the day to variable. I tried using excape character also i.e \' \' ' but no use.
Now my command looks like

DAY='date | cut -f 1 -d \' \''

I am using ksh. and on SUn SOlaris.

thanks
Himanshu
Reply With Quote
  #4  
Old 10-05-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
Cut and paste my statement. The syntax must be exact.
` = back quote
' = single quote
" = double quote
all very different.
Reply With Quote
  #5  
Old 10-05-2005
Registered User
 

Join Date: Sep 2005
Posts: 10
Thanks it worked

Hi
thanks a lot for clearing up the thing. I got it. tht is " ` " (graveascent) to be used when to execute unix command in Shell script.

this thing worked

`date | cut -f 1 -d ' ' `

Thanks again a lot
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0