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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed and parameters scotty_123 Shell Programming and Scripting 7 03-26-2007 05:22 AM
Max NO of parameters Shivdatta Shell Programming and Scripting 1 07-24-2006 09:11 AM
parameters aekaramg20 Shell Programming and Scripting 6 07-11-2006 02:15 AM
Need Parameters Help. james2006 Shell Programming and Scripting 3 06-08-2006 11:46 AM
tar parameters kmar UNIX for Advanced & Expert Users 4 10-23-2001 04:03 AM

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 04-14-2008
jaay jaay is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 6
parameters

i'm supposed to come up with a script that
-accepts a directory as an optional command line parameter
-display an error message and terminates if more than one parameter is provided
-use the current directory if no parameter is provided
-displays an error message and terminates if the provided parameter is not a directory

this is what i came up with..

Code:
if [ $# -ge 2 ]; then
       echo "Too many parameters. Usage: file-info [directory]"
       exit
fi

if [ -d $1 ]; then
       echo "Processing `pwd`: "
       cd $1
       ls -l
       cd
   else
       echo "$1 is not a valid directory... terminating..."
fi
my question is, how do i use the current directory if no parameter is provided?
  #2 (permalink)  
Old 04-14-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Code:
if [ -d "$1" ]; then
  cd "$1"
else
  echo "$0: $1 is not a directory" >&2
  exit 255
fi
ls -l
  #3 (permalink)  
Old 04-14-2008
jaay jaay is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 6
I tried that and it still doesn't work.
  #4 (permalink)  
Old 04-14-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,431
Quote:
Originally Posted by jaay View Post
Code:
if [ $# -ge 2 ]; then
       echo "Too many parameters. Usage: file-info [directory]"
       exit
fi
my question is, how do i use the current directory if no parameter is provided?
If no argument is provided, set the first argument to current directory.
Code:
if [ $# -ge 2 ]; then
       echo "Too many parameters. Usage: file-info [directory]"
       exit
elif [ $# -eq 0 ];then set `pwd`;
fi
  #5 (permalink)  
Old 04-14-2008
jaay jaay is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 6
Thanks! that helped me alot!
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 11:36 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