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
Solved

syntax help on ksh if

Posted on 2009-04-10
8
262 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
  • 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 125 total points
ID: 24116370
how the value is assigned to the variable? Can you share the code so I can look at it?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux : taking backup different mount points under the same directory 8 87
Parse DNS log 3 74
Debugging a shell script 3 31
awk sed 8 65
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

856 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