The UNIX and Linux Forums  


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
Passing parameters to Shell script for GREP command sud.tech Shell Programming and Scripting 1 12-23-2008 08:32 AM
passing oracle parameters back to Shell satnamx Shell Programming and Scripting 4 01-16-2007 09:59 AM
Passing Parameters and getting values back from a c program to Shell script Rajeshsu High Level Programming 5 08-22-2005 04:12 AM
passing parameters from a shell script to sqlplus phani Shell Programming and Scripting 2 03-13-2005 08:41 PM
Passing parameters in script eliguy UNIX for Dummies Questions & Answers 1 08-01-2001 02:13 PM

Reply
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 06-26-2009
wtolentino wtolentino is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 33
Shell Script Passing Parameters For Directory Listing

i have this basic piece of code that i am trying to debug to accept input parameter to be able to display a directory listing of files.


Code:
cd /u02/app/eatv/dev/out
CURDIR=`pwd`
echo directory listing of $CURDIR
echo
if [ $1 -e 0 ]; then
  ls -latr
else
  ls -latr $1
fi

basically if the script does not see any parameter being passed it will display all the file listing of the current directory. and if it find a parameter it display only a specfic files on the directory. the above code does not work and when i run i am getting this error:


Code:
$ sh dir_list_eatv_out.sh *.ini
directory listing of /u02/app/eatv/dev/out

dir_list_eatv_out.sh[20]: -e: 0403-012 A test command parameter is not valid.
ls: 0653-341 The file cca_monthly_load_data.ini does not exist.
$

thanks,
warren
  #2 (permalink)  
Old 06-26-2009
arunsoman80 arunsoman80 is offline
Registered User
  
 

Join Date: Jul 2008
Location: New York
Posts: 45
Try

Code:
if [ $1 -eq 0 ]; then

Or

Code:
if [ $1 = "0" ]; then

regards,
Arun.
  #3 (permalink)  
Old 06-26-2009
wtolentino wtolentino is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 33
thanks. i tried both and still getting an error.


Code:
cd /u02/app/eatv/dev/out
CURDIR=`pwd`
echo directory listing of $CURDIR
echo
if [ $1 -eq 0 ]; then
  ls -latr
else
  ls -latr $1
fi


Code:
$ sh dir_list_eatv_out.sh *.ini
directory listing of /u02/app/eatv/dev/out

dir_list_eatv_out.sh[20]: cca_monthly_load_data.ini: 0403-009 The specified numb
er is not valid for this command.
ls: 0653-341 The file cca_monthly_load_data.ini does not exist.
$


Code:
cd /u02/app/eatv/dev/out
CURDIR=`pwd`
echo directory listing of $CURDIR
echo
if [ $1 = "0" ]; then
  ls -latr
else
  ls -latr $1
fi



Code:
$ sh dir_list_eatv_out.sh *.ini
directory listing of /u02/app/eatv/dev/out

ls: 0653-341 The file cca_monthly_load_data.ini does not exist.
$

  #4 (permalink)  
Old 06-26-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
not sure what you're after, but....

Code:
if [ ${#} -eq 0 ]

  #5 (permalink)  
Old 06-26-2009
wtolentino wtolentino is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 33
thanks. in pseudo code

if input file variable is null then
display the file variable listing
else
dislay all the files in the directory
end if

assuming the i pass a parameter of *.ini it will display all the files having an extension of *.ini otherwise displays all the files on the directory

i tried and still there is an error

Code:
#!/bin/sh
cd /u02/app/eatv/dev/out
CURDIR=`pwd`
echo directory listing of $CURDIR
echo
if [ ${1} -eq 0 ]; then
  ls -latr
else
  ls -latr $1
fi


Code:
$ sh sample.sh *.ini
directory listing of /u02/app/eatv/dev/out

sample.sh[6]: cca_monthly_load_data.ini: 0403-009 The specified number is not va
lid for this command.
ls: 0653-341 The file cca_monthly_load_data.ini does not exist.
$

  #6 (permalink)  
Old 06-26-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 748
Check for an empty parameter:

Code:
cd /u02/app/eatv/dev/out
CURDIR=`pwd`
echo directory listing of $CURDIR
echo
if [ -z "$1" ]; then
  ls -latr
else
  ls -latr $1
fi

  #7 (permalink)  
Old 06-26-2009
wtolentino wtolentino is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 33
i tried that and it did not work.


Code:
$ ls -latr
total 112
drwxr-sr-x    3 ccalftdv ccalogrp        512 Sep 13 2006  dev
-rwxr-xr-x    1 ccalftdv ccalogrp       5586 Jun 08 15:55 cca_monthly_load_file.
ksh
-rwxr--r--    1 ccalftdv ccalogrp       5729 Jun 08 15:55 load_file.ksh
-rwxrwxrwx    1 ccalftdv ccalogrp         63 Jun 11 15:14 display_date.sh
-rwxr-xr-x    1 ccalftdv ccalogrp        680 Jun 25 08:50 cca_monthly_load_data.
ini
drwxr-sr-x    4 ccalftdv ccalogrp        512 Jun 25 08:50 ..
-rw-r--r--    1 ccalftdv ccalogrp        679 Jun 25 10:28 load_data.ini
-rw-r-----    1 ccalftdv ccalogrp       1281 Jun 26 10:10 dir_list_ccalloc_in.sh
-rw-r-----    1 ccalftdv ccalogrp       1281 Jun 26 10:36 dir_list_ccalloc_out.s
h
drwxr-sr-x    3 ccalftdv ccalogrp        512 Jun 26 15:02 .
-rw-r-----    1 ccalftdv ccalogrp        142 Jun 26 16:17 dir_list_eatv_out.sh


$ sh dir_list_eatv_out.sh
directory listing of /u02/app/eatv/dev/out

total 0
drwxrwxr-x    4 oracle   eatvgrp         256 Jun 19 09:41 ..
drwxrwxr-x    2 oracle   eatvgrp         256 Jun 24 08:00 .
$ sh dir_list_eatv_out.sh *.ini
directory listing of /u02/app/eatv/dev/out

ls: 0653-341 The file cca_monthly_load_data.ini does not exist.
$

Reply

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 02:03 AM.


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