Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

syntax help on ksh if

Posted on 2009-04-10
8
Medium Priority
?
268 Views
Last Modified: 2013-12-26
For some reasons, my if test is not working, even though I could echo the right flag value.

Anyway, the cp line always got executed no matter if the variable MOVE_FILE returns Y or N.

What is wrong?

Thanks!
MOVE_FILE=grep...
if [ "${MOVE_FILE}"  = 'Y' ];
then
echo "flag: ${MOVE_FILE}"
cp....
fi

Open in new window

0
Comment
Question by:ommer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 24116235
first you don't need the ; after the if line
2nd use == rather = since I think some versions use it as the assign operator
0
 

Author Comment

by:ommer
ID: 24116347
I have tried those two variations, as well as Y, 'Y', and "Y". But it's still not working.
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 24116370
how the value is assigned to the variable? Can you share the code so I can look at it?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 40

Expert Comment

by:omarfarid
ID: 24116419
here an example :

$ cat 1.ksh
#!/usr/bin/ksh
ans=Y
if [ $ans == "Y" ]
then
    echo yes
fi
ans=N
if [ $ans == "Y" ]
then
    echo yes
else
    echo no
fi
$ ./1.ksh
yes
no
0
 

Author Comment

by:ommer
ID: 24116507
MOVE_FILE=""`grep '^eMvfl>' $LOG_FILE | head -n 1 | cut -d'>' -f2 | cut -d'<' -f1`

thanks!
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24116599
can you show the out put of

grep '^eMvfl>' $LOG_FILE | head -n 1 | cut -d'>' -f2 | cut -d'<' -f1

Also, why do you have "" before `grep '^eMvfl>' $LOG_FILE | head -n 1 | cut -d'>' -f2 | cut -d'<' -f1`
0
 

Author Comment

by:ommer
ID: 24116863
The output as it echo:
flag: Y

But I just found out when I gave N as input, the log file did not get to the echo line. Huh...

Also, the "" before grep is from my co-worker. I am still learning, and have no idea why they are in. And I will try to go wihtout them in a minute.
0
 

Author Closing Comment

by:ommer
ID: 31568923
It turned out that error was from the grep line.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question