Shell Problem

Hi all,

until yesturday grep command was running in KSH ....
I was executing this command
ls -l | grep *.sh

But today its not working at all ...

Should I check any of the setting ...
I am not getting whats the problem ...

I have relogged to unix box but it didn't work ....

Please help,
Dhananjay

Oh !!! Why ls -l | grep *.sh when you can do ls -l *.sh. That should show you whether there are any .sh files.

infact i want to find out the files on particular date ...
say of 3 Nov ...
so i was using grep "3 Nov" ....

but today its not working

You could try

ls -l | grep "Nov 3"

If nothing turns up, then probably there is not file from that day.

I am doing the same ... but it is not working ..
can any command cause this problem ....
or is shell corrupted .... Do u have any idea about it ...

You should minimally say what the error message is there are any. Or what you are expecting and you are actually got. Cant proceed further, without any clues from your side.

So strange... OK, let's make a check list :slight_smile: :

  • ls -l /usr/bin/grep (or wherever it is)
  • whoami
  • file /usr/bin/grep (or wherever it is)
  • try with awk: ls -l | awk '/Nov 3/ {print}'
  • And of course, as vino says, any error text would be appreciated.
    And show us the results, please.
    Regards.

I do find this on the prompt ..( it doesnt throw any error message )
unix > ls
a.sh abc.txt
b.sh prod.tar
c.sh leon.exe

after this I am using .............

unix > ls -l | grep *.sh
unix >

( only prompt is returned ...no error message nothing )
( I have relogged the unix box ... but this simple command doesn't work )

should have anything corrupted ?
or has executing any other command has disabled grep command ...No clue

Have you tryed everything I suggested? One more thing to add to the list:

  • echo $?
    just after the command.

Without all that info, I'm afraid I won't be able to help you...

ls -l
echo $?
whoami ..all are giving proper output

if i use
whoami | grep "mar" ( it gives proper o/p )

but when I use ls -l | grep *.sh .............its not working

Try

ls | grep ".sh"

I created files by that name and got the output

  • is a special character for grep(used in regular expressions)

Thanks Vish ....
It has worked .....

but why it happens ...
If I use * ... then it should consider it as 0 or more occurances of a character ...

I just wanted to see it... OK, I give up: I will believe in what you say and this is my conclusion:

  • The grep command si working perfectly.

From what I know * is 0 or more occurrence of the previous character. Since there is no previous character in expression *.sh , it fails. Not sure which character it assumes there.

Try

 grep .*\.sh 

it works. This checks for any character(s) followed by .sh

In the example provided "Nov 3" should have two spaces before the 3. The day is right alligned.

# ls -l | grep 'Oct 3'
# ls -l | grep 'Oct  3'
-rw-r--r--   1 root     root           0 Oct  3 12:12 file
#

Also se the post previous to this one for the correct wat to grep for all files ending in .sh