LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can sum1 explain how this script works in linux....... (https://www.linuxquestions.org/questions/linux-newbie-8/can-sum1-explain-how-this-script-works-in-linux-691113/)

sp1dy7 12-16-2008 11:48 PM

Can sum1 explain how this script works in linux.......
 
for i in `ls -1r`;do sh $i; done;

joshuas3521 12-17-2008 02:16 AM

for i in `ls -1r`; do
sh $i;
done;

It runs all shell scripts in the current directory. It translates out to this:

for every file 'i' in the current directory
call "sh i" (where i is the name of the file)

so, if you had a directory that had the following files:
bar.sh
e.sh
foo.sh
x.sh

it would execute
Code:

sh x.sh
sh foo.sh
sh e.sh
sh bar.sh

The -1r argument simply tells ls to list the files in reverse order, one per line.


All times are GMT -5. The time now is 01:00 PM.