Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if a given directory exits. 1

Status
Not open for further replies.

caesarkim

Programmer
Oct 30, 2003
56
US
does anybody know a good tutorial about shell scripting?

I just started learning a shell script.

I just want to know how to check if a given directory exists and how to write to a plain text file.

Thanks.
 
first make sure your index file is up to date:

updatedb

Then "locate directory"

Use pico to create a text file. Or you could use nano:

pico myfile.txt or nano myfile.txt

Write to it, then press CTRL+X (Save it!)
 
Tutorials:

Find out if directiry exist:

if [ -d /My/directory/psth ]
then
echo "Exists"
else
echo "Doesn't exist"
fi
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

To write to file:

1) Use redirection:

echo "First line" >MyFile

2) Use and editor: ed, ex vi, emacs, pico, etc...

3) Read the tutorials.



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
My favouries are the O'Reiley series. This is a shamesless plug, and I don't work for them. IN particular you might want to look at this Unix site which I still refer to from time to time.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top