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"

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

Also check that you have right amount of spaces in if [ ]

How do I change the file extension using egrep or expr

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

Thanks!

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

How do I change the file extension using egrep or expr

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

Thanks!

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.