Solved

syntax help on ksh if

Posted on 2009-04-10
8
261 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How should I mount this 3 TB USB Hard disk to my Linux server? 9 110
linux pull logs and export FTP 4 70
Shell Script on AIX 7 95
Help With Shell Script Centos 6 6 52
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…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

776 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