Shell Script Passing Parameters For Directory Listing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Passing Parameters For Directory Listing
# 1  
Old 06-26-2009
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  
Old 06-26-2009
Try
Code:
if [ $1 -eq 0 ]; then

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

regards,
Arun.
# 3  
Old 06-26-2009
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  
Old 06-26-2009
not sure what you're after, but....
Code:
if [ ${#} -eq 0 ]

# 5  
Old 06-26-2009
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  
Old 06-26-2009
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  
Old 06-26-2009
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.
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to run sql query having a long listing of parameters

Hi, I have a query regarding execution of a sql query having long listing of parameters ..I need to execute this query inside a shell script. The scenario is like.... Suppose I have a file abc.txt that has the card numbers..it could be in thousands.. then I need to fire a query like ... (12 Replies)
Discussion started by: vsachan
12 Replies

2. Shell Programming and Scripting

Shell Script passing parameters to sqlplus code

Hello All, I am interested in finding out a way to pass parameters that are entered at the prompt from HP unix and passed to SQLPlus code with a Shell Script. Is this possible? Thanks (4 Replies)
Discussion started by: compprog11
4 Replies

3. Shell Programming and Scripting

passing parameters to the script

how can i make a script to run only when parameters are given, if parameters are not given it should through an error , saying "please enter a parameter" for ex: i want a find command to run only when the parameters are given (4 Replies)
Discussion started by: knip
4 Replies

4. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

5. Shell Programming and Scripting

specified path name is too long passing parameters to awk via shell script

Hello, I have this shell script that runs awk code by passing in parameters however now it doesn't work anymore with the parameters and I don't know why. It removes duplicates from an input file based on a part of the last field and a key column. It removes the record with the older datetime... (0 Replies)
Discussion started by: script_op2a
0 Replies

6. Shell Programming and Scripting

Unix Shell Script to loop over Directory and send Filesname as parameters

Hi there I'm new to UNIX scripting; I’m stuck with the following I have an Oracle SQL script that takes three parameters 1- File Name 2- File Path 3- File creation date Under UNIX I have a folder where files will be placed frequently and I need to upload those files to Oracle, what I need... (3 Replies)
Discussion started by: windjashi
3 Replies

7. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

8. Shell Programming and Scripting

passing oracle parameters back to Shell

Hi All, Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure: eg #username='scott' #password='tiger' #database='orcl' username='ITGCD03D03' password='tC5epIew' database='ITGCD03D' sqlplus -s... (4 Replies)
Discussion started by: satnamx
4 Replies

9. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

10. Shell Programming and Scripting

passing parameters from a shell script to sqlplus

Hi , I want to pass parameters from a shell script to a sql script and use the parameter in the sql query ..and then I want to spool a particular select query on to my unix box... for 4 different locations by writing only one sql script Right now no file is generated on the unix box...it is a... (2 Replies)
Discussion started by: phani
2 Replies
Login or Register to Ask a Question