LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-26-2007, 05:54 PM   #1
efus
Member
 
Registered: Jun 2003
Location: Odense, Denmark
Distribution: Fedora
Posts: 32

Rep: Reputation: 15
file or directory? bash script


I am working on a little bash scripting project.
I need to make a function that determines whether a path is a file or a directory.

so if I have a path: /home/user/something
how do I find out if "something" is a file or a directory?
 
Old 04-26-2007, 05:59 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
"so if I have a path: /home/user/something
how do I find out if "something" is a file or a directory?"

test -d /home/user/something

see:

man test

------------------
Steve Stites
 
Old 04-26-2007, 06:06 PM   #3
hollywoodb
Member
 
Registered: Aug 2003
Location: Minnesota, U.S.A.
Distribution: Debian, openSUSE
Posts: 400

Rep: Reputation: 30
Code:
man test
for example, you can use it in an if statement if you so desire:
Code:
if [ -d /some/path ]; then
    <do something>
fi
 
Old 04-26-2007, 06:11 PM   #4
efus
Member
 
Registered: Jun 2003
Location: Odense, Denmark
Distribution: Fedora
Posts: 32

Original Poster
Rep: Reputation: 15
that did the trick, thank you both
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory variables in a bash script madtinkerer Programming 9 12-04-2006 12:30 PM
changing directory in bash (or other) script zefram Linux - General 2 09-16-2006 10:41 AM
How do I check for directory in bash script? nadavvin Programming 1 09-13-2006 04:03 PM
Bash script to strip a certain directory out of directories in a directory? rylan76 Linux - General 3 08-29-2006 11:35 AM
triggering bash script if directory modified cbb Linux - Software 1 10-23-2004 07:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration