Dear I need some detailed explanation about the following program
for file in `ls`
do day=`ls -lt $file|cut -d' ' -f6` if [[ $day = "2007-11-21" ]] then echo "$file matched" fi done |
Please re-read the forum guidelines on how to create a useful question.
That said, you'll find a nearly complete explanation here: http://mywiki.wooledge.org/ParsingLs http://mywiki.wooledge.org/BashGuide Which specific parts do you have questions about? |
Besides the accurate advice from Turbocapitalist.
Please use [code][/code] tags around code to maintain spacing and formatting. This is not a program, it is a script. Have you run it? |
Quote:
https://www.linuxquestions.org/quest...8/#post2965915 Did you read that thread, where it's explained, and its usage case? Did you LOOK at the script line by line? See the commands it's using and read their man pages?? After being here for ELEVEN YEARS, you should know to do basic research first. |
Quote:
Code:
#!/bin/bash Code:
day=`ls -lt $file|cut -d' ' -f6` Code:
Code:
for file in `ls` Doing that will give you your explanation about the code in question. Experiment with the loops to gain a better understanding of what they do and how to use them to your advantage. the quick of it all is, that it loops through all of the output/files in a given directory, cuts off the front of the output 'ls -lt' gives out, then puts that into a variable, then checks what that is against the condition in the test, then gives the results if a match is found. looking at the example that I gave showing the output that code will never work. using 7 for the placement to cut gives me this Code:
$ var="$(ls -lt . | cut -d' ' -f7)" Code:
for f in `ls` ; do echo $(ls -lt "$f" | cut -d' ' -f6) ; done Code:
I found this, 'll --full-time' Code:
ll --full-time | awk '{print $6}' And be mindful about using code tags in here. cheers! :D |
Quote:
I'm personally wondering how you managed to locate it, and if you care to share that. The original question and thread title are inadequate, and these were points which Turbocapitalist covered very well. Did notice that all of saleemsupra's posts seem to be lacking in great detail, and still chose to not offer much comment. Knowing now that the script in question is a copy from a far older question, it does change my opinion a bit. I'm not sure there's any particular LQ Rules violation. But meanwhile I would say that it is poor posting on your part saleemsupra to have been on this site for your duration and never taken the time to offer any real feedback when people have responded to your other questions, nor to update your threads when people ask you for information. |
you might want to insert set -xv at the beginning of your script. You will see what's happening.
|
All times are GMT -5. The time now is 01:55 AM. |