Simple question on $VAR = num


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple question on $VAR = num
# 1  
Old 11-15-2010
Simple question on $VAR = num

Hello,
I am a begginer on shell scripting and I need a simple advice.
I have the following script.
The output of DATE is gathered from Oracle and it will be 101115 (for todays date)
Therefore the DAY will be sed-ed , and it contains 15
Code:
#!/bin/sh
DATE=`${LIB}/dt_YYMMDD 0`
DAY=`echo $DATE| sed 's/....\(.*\)/\1/'`
if [ $DAY == 15 ];
then
  echo is the same
fi

However when I am trying to execute the script, I get:
Code:
./sedtest2.sh[6]: ==: A test command parameter is not valid.

I believe it is something wrong in my comparison statement.

Any help will be much appreciated.
Thank you !

Last edited by Franklin52; 11-15-2010 at 05:51 AM.. Reason: Please use code tags and indent your code
# 2  
Old 11-15-2010
Code:
#!/bin/sh
DATE=`${LIB}/dt_YYMMDD 0`
DAY=`echo $DATE| sed 's/^....//'
if [ $DAY == "15" ];
then
  echo is the same
fi

By the way, you can run command date +%d to get the day directly
This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 11-15-2010
I tried that, but I get the same error Smilie
# 4  
Old 11-15-2010
hmm try..
Code:
if [ "${DAY}" = "15" ]

This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 11-15-2010
Thank you all Smilie
# 6  
Old 11-15-2010
You can find out how comparisons work in the man page of "test" ("man test").

The opening square bracket ("[") is in fact just an alias or link for "/usr/bin/test", to make shell code more readable:

Code:
if [ "$x" = "a" ] ; then

and

Code:
 if /usr/bin/test "$x" = "a" ; then

is basically the same, the former is just "more natural" to read than the latter. "if" just takes the return code of the following command and "test" returns "0" when the comparison is true, otherwise it returns "1". The following would also work:

Code:
if 0 ; then

or
Code:
if 1 ; then

The first one would always execute the "then"-branch, the second one always the "else"-branch..

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

2. UNIX for Dummies Questions & Answers

simple question

hi everybody; trying to c unix programming and ive stucked with a problem: simple program filedr=open("tempfile",O_RDWR|O_TRUNC,0); write(filedr,msg1,6); int i; i=read(filedr,msg3,4); it returns 0 bytes read ... why? well if i try to poll() before read , it doesnt indicate POLLHUP or... (4 Replies)
Discussion started by: IdleProc
4 Replies

3. UNIX for Dummies Questions & Answers

/VAR/SPOOL/MAIL question

Hi, We have all the user account in a home direcory where their mail is stored and retrieved by email clients. We do however have /var/spool/mail with all the user accounts in it as well Our sendmail.cf is configured to use /var/spool/mqueue as the queue so .what is /var/spool/mail being used... (3 Replies)
Discussion started by: mojoman
3 Replies

4. UNIX for Dummies Questions & Answers

Simple Question

Hi Guys, I've been learning UNIX for the past couple of days and I came across this exercise, I can't get my head around it, so I would be ever so grateful if I could receive some sort of help or direction with this. Create a file with x amount of lines in it, the content of your choice. ... (3 Replies)
Discussion started by: aforball
3 Replies

5. Shell Programming and Scripting

Simple Question

If given some output such as: "I'm having a senior moment" How do you print the last six characters to the screen? I'm thinking with awk or sed but can't remember how. (1 Reply)
Discussion started by: stepnkev
1 Replies

6. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

7. UNIX for Dummies Questions & Answers

simple if then fi question

i'm trying to make a script that prints the name of the script for any command line parameter, here is what i have, and get `]]' unexpected: what am i doing wrong? (3 Replies)
Discussion started by: tefflox
3 Replies

8. UNIX for Dummies Questions & Answers

Very simple question

I'm new to unix commands and am wondering how you could create a page with html tags in it. echo "<b>Test</b>" > test.html doesn't work because of the tags. How would I do this. (4 Replies)
Discussion started by: roger19
4 Replies

9. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

10. UNIX for Dummies Questions & Answers

Simple question

I am taking an intro to unix class and I can not figure out how to do part of the question. I am writing script to be exictued by a program in the tutoral. Question: Write every line containing the word ``delete'' produced by ``man mail'' into a file called ``delete''. Hint: What does using... (1 Reply)
Discussion started by: weathergirl
1 Replies
Login or Register to Ask a Question