Solved

syntax help on ksh if

Posted on 2009-04-10
8
263 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Launch Process with NOT as Administrator 15 115
How to check the PVU´s on AIX TSM servers? 3 119
Linux Scripting 3 165
VBA Shell can't Find Word document 11 128
Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

756 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