LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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: Arch
Posts: 31

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
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,509

Rep: Reputation: 177Reputation: 177
"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: Arch
Posts: 31

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 07:53 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration