From my workbook, a function to display filename created on the user specified date:
function lsd
{
date=$1
ls -l | grep -i "^.\{42\}$date" | cut -c55-
}
The workbook notes the columns that need to be specified will probably differ on different terminals, operating systems. When I use ls -l in my terminal, the first character for the date starts at column 35 (in DD Month format) and the first character for the filename column starts at 48. So, what I wrote:
1 #!/bin/bash
2
3 lsd ()
4 {
5 date=$1
6 ls -l | grep -i "^.\{35\}$date" | cut -c48-
7 }
If I do
8 $lsd
and run the script like this:
./lsd "22 aug"
I get a list of all the filenames in the directory no matter what their creation date is. Not what I want. I don't know why this happens.
If I change the function call line (someone suggested I do this) to
8 lsd $1
and enter ./lsd "22 aug"
in terminal again, I get a list of all the filenames that were created on the 22 day of any month, not just August.
I don't know why 8 lsd
brings up all the file names. I don't know why changing that to 8 lsd $1
brings up only the files created on the 22nd day irrespective of specified month. I'm not sure what I'm doing wrong here, or if there is some mistake in the work book or it is outdated.