#!/bin/sh
pdir=`pwd`
if [ $# -lt 1 ]; then
echo current directory $pdir
ls -altr
echo
fi
for f in $*
do
# directory
if [ -d $f ]; then
echo current directory $f
cd $f
ls -latr
echo
fi
# but you can test file/dir
# regular file only
if [ -f $f ]; then
pfile=`basename $f`
pdir=`dirname $f`
echo current directory $pdir
cd $pdir
ls -altr $pfile
echo
fi
done
thanks that works when i added the change directory cd command. lastly is to fix the display. when i run it gives me this directory listing where the display for the current directory was repeated.
Code:
$ sh dir_file_list.sh /u02/app/eatv/dev/out/*.txt
current directory /u02/app/eatv/dev/out
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 09:30 sample.txt
current directory /u02/app/eatv/dev/out
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample2.txt
current directory /u02/app/eatv/dev/out
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample3.txt
$
it should look like this:
Code:
current directory /u02/app/eatv/dev/out
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 09:30 sample.txt
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample2.txt
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample3.txt
---------- Post updated at 01:09 PM ---------- Previous update was at 12:38 PM ----------
Code:
pdir=`pwd`
if [ -f $# ]; then
pfile=`basename $#`
pdir=`dirname $#`
fi
if [ -d $# ]; then
pdir=`$#`
fi
echo current directory $pdir
if [ $# -lt 1 ]; then
ls -altr
echo
fi
for f in $*
do
# directory
if [ -d $f ]; then
cd $f
ls -latr
echo
fi
# but you can test file/dir
# regular file only
if [ -f $f ]; then
pfile=`basename $f`
pdir=`dirname $f`
cd $pdir
ls -altr $pfile
fi
done
i modified the script a bit and i was able to get the expected results.
Code:
$ sh dir_file_list.sh
current directory /export/home/ccalftdv/apps
total 152
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
-rw-r--r-- 1 ccalftdv ccalogrp 679 Jun 25 10:28 load_data.ini
drwxr-sr-x 4 ccalftdv ccalogrp 512 Jun 29 13:53 ..
-rw-r----- 1 ccalftdv ccalogrp 1298 Jun 30 08:26 dir_list_ccalloc_in.s
-rw-r----- 1 ccalftdv ccalogrp 1298 Jun 30 08:26 dir_list_ccalloc_out.
h
-rw-r----- 1 ccalftdv ccalogrp 166 Jun 30 09:32 sample.sh
-rw-r----- 1 ccalftdv ccalogrp 1357 Jun 30 09:39 dir_list_eatv_out.sh
-rw-r--r-- 1 ccalftdv ccalogrp 385 Jun 30 10:49 sample2.sh
-rw-r--r-- 1 ccalftdv ccalogrp 375 Jun 30 11:13 sample3.sh
-rw-r--r-- 1 ccalftdv ccalogrp 9 Jun 30 17:04 sample2.txtw
-rw-r--r-- 1 ccalftdv ccalogrp 454 Jul 01 12:54 dir_file_list.sh.bak
drwxr-sr-x 3 ccalftdv ccalogrp 512 Jul 01 12:54 .
-rw-r--r-- 1 ccalftdv ccalogrp 1595 Jul 01 12:58 dir_file_list.sh
$ sh dir_file_list.sh /u02/app/eatv/dev/out
current directory /export/home/ccalftdv/apps
total 32
drwxrwxr-x 4 oracle eatvgrp 256 Jun 19 09:41 ..
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 09:30 sample.csv
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 09:30 sample.txt
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample2.txt
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample3.txt
drwxrwxr-x 2 oracle eatvgrp 256 Jun 30 17:05 .
$ sh dir_file_list.sh /u02/app/eatv/dev/out/*.csv
current directory /export/home/ccalftdv/apps
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 09:30 sample.csv
$ sh dir_file_list.sh /u02/app/eatv/dev/out/*.txt
current directory /export/home/ccalftdv/apps
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 09:30 sample.txt
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample2.txt
-rw-r--r-- 1 ccalftdv ccalogrp 7 Jun 30 17:05 sample3.txt
$
---------- Post updated at 03:38 PM ---------- Previous update was at 01:09 PM ----------
Code:
pdir=`pwd`
if [ $# -lt 1 ]; then
echo current directory $pdir
ls -latr
echo
else
p1=$1
if [ -d $p1 ]; then
pdir=$p1
echo current directory $pdir
cd $pdir
ls -latr
echo
elif [ -f $p1 ]; then
pdir=`dirname $p1`
echo current directory $pdir
cd $pdir
for f in $*
do
pfile=`basename $f`
ls -altr $pfile
done
else
echo $p1 not found
fi
fi
# put a white space
Can anyone help me how to write a shell script which accepts input parameter. My requirement is as follows:
I need to run a shell script with a input parameter, and inside the script i will create a file with this input parameter name.
Please help me out to create such a shell script.
... (1 Reply)
Hi,
My script expects 2 inputs and one of them is supposed to be time, I would like to check if the given input is in validate format (i.e. 16:00), could anyone help me out here? thanks! (1 Reply)
Hi,
My script takes in one input parameter($1-email id) on the command line...
The script contains something like this...
awk '$1 == 400' abc.log >def.log
mail -s subject $1 <def.log
abc.log looks something like this...
300 222 330 123 445
400 098 890 727 663
How do i make the... (3 Replies)
Hi,
i am new to awk. I am using csv2pipe script(shown below)
BEGIN { FS=SUBSEP; OFS="|" }
{
result = setcsv($0, ",")
print
}
# setcsv(str, sep) - parse CSV (MS specification) input
# str, the string to be parsed. (Most likely $0.)
# sep, the separator between the values.
#
#... (6 Replies)
hi
I have a shell script say primary.sh . There is a file called params
my scenario is
primary.sh should read all the values and echo it
for example
i should pass like
$primary.sh params
output would be
Abc
... (2 Replies)
Hi all
i need to check that if user has passed any input parameter while executing he shell script like
./test1.sh -a"-v"
then do smothing
if user execute the script without giving input paramater then
./test1.sh
then do something
how can we check this input parameter (6 Replies)
Hello Forum.
I have the following files in one directory:
abc_july01_2013.txt
abc_july02_2013.txt
abc_july03_2013.txt
abc_july04_2013.txt
abc_july05_2013.txt
abc_july06_2013.txt
abc_july07_2013.txt
abc_july08_2013.txt
If I want to be able to keep the last 5 versions of the file and... (4 Replies)
OS version: RHEL 6.7
myTextFile.txt file is referred within Script1.sh script,
I only execute Script1.sh and I want the input variable to be passed inside myTextFile.txt . Any idea how I can do this ?
$ cat script1.sh
cat myTextFile.txt
$ cat myTextFile.txt
$1
Requirement1.... (4 Replies)
Hi Guys,
I am having a script file where in getting input parameter as string. I need to assign the variable but not able to achieve
#!/bin/bash
input=$1
replace=string_$input_string2
echo $replace
I am getting but should get string_<input_value>_string2
string_ (1 Reply)