User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,444 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,604 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 851 | Replies: 6
Reply
Join Date: Oct 2007
Posts: 13
Reputation: acwbrat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
acwbrat acwbrat is offline Offline
Newbie Poster

Desparate Need of Help!

  #1  
Oct 16th, 2007
I am new to Daniweb and I need some help with my programming code in Unix.

I have written an if-else statement for Bash Scripting and it doesn't work. I have been told that variables would help with my code but I still don't see my program working.

I'm suppose to use a script that will check if it exists and if not, a termination message appears.

I did this:

if [ -e $x ]

then

echo "file exists"

else

echo "file doesn't exists"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 306
Reputation: eggi is on a distinguished road 
Rep Power: 2
Solved Threads: 29
eggi eggi is offline Offline
Posting Whiz

Re: Desparate Need of Help!

  #2  
Oct 18th, 2007
Hey There,

You've pretty much got it. Just an inch away. All you need to do is complete the if-then statement with fi.

if [ -e $x ]
then
echo "file exists"
else
echo "file doesn't exists"
fi

That should do it. Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 1,012
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 6
Solved Threads: 68
ithelp ithelp is offline Offline
Veteran Poster

Re: Desparate Need of Help!

  #3  
Oct 18th, 2007
Also check that you have right amount of spaces in if [ ]
Reply With Quote  
Join Date: Oct 2007
Posts: 13
Reputation: acwbrat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
acwbrat acwbrat is offline Offline
Newbie Poster

Re: Desparate Need of Help!

  #4  
Oct 19th, 2007
How do I change the file extension using egrep or expr

Ex: me.cpp to me.out or me.cpp to me.exe

Thanks!
Reply With Quote  
Join Date: Oct 2007
Posts: 306
Reputation: eggi is on a distinguished road 
Rep Power: 2
Solved Threads: 29
eggi eggi is offline Offline
Posting Whiz

Re: Desparate Need of Help!

  #5  
Oct 19th, 2007
Hey There,

I'm not sure if you can change the file extension with grep or expr (just check for the different file extensions.

If you want to change the extension, sed is built-in to everything and might be the easiest thing to use:

#!/bin/ksh

filename=me.cpp
newfilename=`echo $filename|sed 's/cpp/out'`
echo "OLD $filename NEW $newfilename"

If I'm way off on my understanding of what you're looking for, just let me know

,Mike

Originally Posted by acwbrat View Post
How do I change the file extension using egrep or expr

Ex: me.cpp to me.out or me.cpp to me.exe

Thanks!
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Oct 2007
Posts: 13
Reputation: acwbrat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
acwbrat acwbrat is offline Offline
Newbie Poster

Solution Re: Desparate Need of Help!

  #6  
Oct 19th, 2007
THANK YOU EGGI!

I just wanted to know if there was a code to incorporate egrep or expr when manipulating strings...the file extension rather. From .cpp to .out

That it all.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,509
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: Desparate Need of Help!

  #7  
Oct 20th, 2007
And you have your very own thread on this topic. Keep the discussion there. And once again, I do not know why you are so fixated on using expr.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC