LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-10-2010, 05:39 AM   #1
BryDawg
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Rep: Reputation: 0
Smile bash directory


Hey Guys! I am trying to figure out how to make my while loop determine if the parameter typed in is a directory, my loop looks like this, but for some reason, every time i run ./myscript /etc or any other directory, it does not recognize it as a directory, hope you can help,

bmt



# make_page - A script to mimic the tree command
while [ "$1" != "" ]; do
case $1 in
-d | $DIRECTORY ) shift
my_tree
;;
-h | --help ) helpmedog
exit
;;
* ) psyke
exit 1

esac
shift
done
 
Old 03-10-2010, 05:51 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I can't see anything looks for a directory. there's no test command or anything. How are you expecting this decision to be made??

[ -d "$1" ] && some_directory_function
 
Old 03-10-2010, 06:16 AM   #3
BryDawg
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Original Poster
Rep: Reputation: 0
that is what I am asking.
 
Old 03-10-2010, 06:22 AM   #4
BryDawg
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Original Poster
Rep: Reputation: 0
so like if somebody enters a directory after my file, i need something to let my bash script send that directory to a function that will list it arraigned however i feel fit. ( like tree command) . .
 
Old 03-10-2010, 06:32 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by BryDawg View Post
that is what I am asking.
Well---he showed you an example of how to use the "test" command ("[" is a synonym for "test")

Note: In your "case" statement you appear to be looking for the value of the first passed arguement ($1). In the first case, you are looking for a value of "-d" or a value equal to the contents of the variable "DIRECTORY". What was your intent here?
 
Old 03-10-2010, 06:32 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well I gave you a simple example to do something if $1 is a valid directory.
 
Old 03-10-2010, 06:44 AM   #7
BryDawg
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Yea that is my intent, but when i send in a directory as a $1, it does to pick it up as a parameter, the purpose of the loop is to continually search until it comes up with something, it might not even be the first argument all the time, I just what the argument that is passed as a directory to be collected and sent to a function.

Last edited by BryDawg; 03-10-2010 at 07:14 AM.
 
Old 03-10-2010, 07:15 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by BryDawg View Post
Yea that is my intent, but when i send in a directory as a $1, it does to pick it up as a parameter, the purpose of the loop is to continually search until it comes up with something
I do not understand this.....Please give an example of how you are calling the script: Show the command used and the result (cut and paste from your terminal).

Note: where does the variable "DIRECTORY" get set? Making it all caps implies that it is a standard environment variable, but that's note the case--at least on my system.
 
Old 03-10-2010, 08:14 AM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
a loop of what?? you're shifting through all the parameters passed to a script, can't imagine any functional implementation of a tree traversal program where that'd make sense.
 
  


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
Bash Directory Variables DrPoodle Programming 5 07-24-2008 08:23 PM
Bash scripting: "line [...]: [directory]: is a directory " ? serious Linux - Newbie 1 10-20-2007 12:08 PM
getting directory in bash script firsttux Programming 4 10-08-2007 01:07 AM
Bash script to strip a certain directory out of directories in a directory? rylan76 Linux - General 3 08-29-2006 11:35 AM
bash: su - changes directory to /root arpi Linux - Software 2 06-11-2004 08:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:55 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