The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
listing of directories with / at end...without ls -F vasanthan UNIX for Dummies Questions & Answers 10 04-16-2008 05:34 AM
listing of directories with / ...not to use ls -F vasanthan UNIX for Advanced & Expert Users 1 04-16-2008 04:20 AM
Listing directories and sub directories jinxor UNIX for Advanced & Expert Users 3 03-11-2008 10:27 AM
Listing Unique directories. deepakwins UNIX for Dummies Questions & Answers 2 01-23-2008 06:14 PM
files and directories listing bbolson UNIX for Dummies Questions & Answers 1 12-11-2001 01:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-23-2005
GMMike GMMike is offline
Registered User
  
 

Join Date: Sep 2004
Posts: 32
Listing directories and ${1:+$1/}*

Hi
I have 2 questions:

Q1 - What does
${1:+$1/}*
mean? I guess it lists all files in current directory - Could any one explain how this expression works?

Q2 - I am trying to list directories only in current path - I know that ls could be used but I thought I'd give find a try. I need to list only high level directories (no sub directories or files)

find has option -type d however, the following command always lists sub-directories:

find . -type d

I tried to use maxdepth as in

find . -type d maxdepth 0

but that gives me syntax error.

So my Q2 is:
How to use fiind command to list top level directories only?

Thanks much.
  #2 (permalink)  
Old 01-23-2005
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Regarding ${1:+1\}*

In Korn shell you can use expressions such as this to set default values for variables. The above statement checks to see that if $1 (the first input variable) is set, if it is then $1\* is substituted. Can you post the complete line in your script where this is used? Also, there are other builtins, please see the botton of this thread

Regarding listing directories using find. Well thats sort of using a hammer to break an egg Plus, by default, find is recursive in nature. Try using ls | grep ^d or something like that.
  #3 (permalink)  
Old 01-24-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,122
Please navigate:
our home page -> Answers to Frequently Asked Questions -> advanced/complex uses of the find command
  #4 (permalink)  
Old 01-24-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Quote:

Q1 - What does
${1:+$1/}*
mean? I guess it lists all files in current directory - Could any one explain how this expression works?
Above expression is trying to list files (with relative path including paramter passed as first arg ) of the directory passed as argument.
If argument is not passed it lists the files/directories in the current directory.

See below ...

$ cat x.sh
echo ${1:+$1/}*

$ ./x.sh 1234
1234/subdir1 1234/subdir2 1234/subdir3 1234/subdir4 1234/subdir5

$ ls 1234
subdir1 subdir2 subdir3 subdir4 subdir5
$ ./x.sh
1234
  #5 (permalink)  
Old 01-24-2005
GMMike GMMike is offline
Registered User
  
 

Join Date: Sep 2004
Posts: 32
Thanks

Thanks for your help guys.

As per google's inquiry about the context, it appeared in a ksh script that goes through files and directories and does operations on them, it looked like this:

for filename in ${1:+$1/}*; do
....
done

I personlay think that this form of coding in ksh is not comfortable. It is more compact but then again not instantly readable...
  #6 (permalink)  
Old 01-24-2005
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Quote:
I personlay think that this form of coding in ksh is not comfortable. It is more compact but then again not instantly readable
Builtins such as that are definitely useful and you will undoubtedly see them again. You may not be too comfortable with them now, but as you learn the language you will find that they provide quite a lot of value. Happy coding.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0