Solved

syntax help on ksh if

Posted on 2009-04-10
8
258 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
Comment Utility
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
Comment Utility
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
Comment Utility
how the value is assigned to the variable? Can you share the code so I can look at it?
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

thanks!
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
Comment Utility
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
Comment Utility
It turned out that error was from the grep line.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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 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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now