avhg1
1
Can anyone tell me what I'm doing wrong? All my output files are blank. Any suggestions would be great.
#check for arguements & exit if none are supplied
if test $# -lt 1 ; then
echo "No file pattern supplied"
else
PStr= echo "$@" |tr " " "|"
#echo $PStr
#ls -l > tmp1
#ls -l > tmp2
ls -l | egrep '$PStr'| tr -s " "| cut -f9 -d" " > tmp1
ls -l |egrep '$PStr' | tr -s " " | cut -f1,5 -d" " | paste - tmp1 > tmp2
ls -lu |egrep '$PStr' |tr -s " " |cut -f6,7,8 -d" " |paste - tmp2 > tmp1
ls -l |egrep '$PStr' |tr -s " "|cut -f6,7,8 -d" " |paste - tmp1 > tmp2
echo "Modified Accessed Permission Size Name"
cat tmp2
#rm tmp1
#rm tmp2
fi
Thanks,
Mike
I usu create if then statements where:
1) I have the positive response as the "THEN" branch.
2) I have the negative response be the "ELSE" branch
It makes it easier to read and more consistent.
if [ $# -mt 1 ]; then
PStr= echo "$@" |tr " " "|"
else
echo "No file pattern supplied"
I think your syntax is wrong for the Test syntax.... not sure though with out testing it...
EDIT: Also, not sure about your variable $# what is the # you are using? Is that your variable... I would pic something like $VAR instead.
avhg1, what is some example input into this script? It looks like you're trying to accept user input... or are you feeding a file into the script?
Also, what are you trying to accomplish here? There may be an easier way to do what you want...
Ygor
4
There are two problems:
(1) this line is missing some `back quotes`...
PStr= echo "$@" |tr " " "|"
(2) these lines need "double quotes" not 'single quotes'....
ls -l | egrep '$PStr'| tr -s " "| cut -f9 -d" " > tmp1
ls -l |egrep '$PStr' | tr -s " " | cut -f1,5 -d" " | paste - tmp1 > tmp2
ls -lu |egrep '$PStr' |tr -s " " |cut -f6,7,8 -d" " |paste - tmp2 > tmp1
ls -l |egrep '$PStr' |tr -s " "|cut -f6,7,8 -d" " |paste - tmp1 > tmp2