LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-18-2007, 07:48 PM   #1
winstonblue
LQ Newbie
 
Registered: May 2007
Posts: 5

Rep: Reputation: 0
minix question


Hi all

Could anybody explain the basic functions of the below bash script and what exactly is doing?
Thank you.

#!/bin/sh
# uP2P.sh 0.0.1, 436 characters (excluding comments)
[ $3 ]&&export W=$1 H="$2 $3" K=`mktemp`;Z=/dev/null;e(){ echo "$*";};n(){
nc $* 2>$Z;};x(){ nc -lp ${H#* } -e $1 &>$Z <$Z&};f(){ cat $K|while read h;do
e $W $1 "$2"|n $h;done };case $# in 4)e $W s "$4"|n $H|while read h p f; do
e $W g "$f"|n $h $p>"$f";done;;5)e $H>$K;e $W d $H|n $4 $5>>$K;x $0;;0)x $0
read w c r;[ $W = $w ]&&case $c in s)f l "$r";;g)cat "$r";;a)e $r>>$K;;d)cat $K
f a "$r";;l)ls|grep "$r"|sed "s/^/$H /";;esac;;esac
 
Old 05-18-2007, 10:48 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Have you seen this page: http://www.crossflux.org/uP2P/ ?
 
Old 05-19-2007, 07:48 PM   #3
winstonblue
LQ Newbie
 
Registered: May 2007
Posts: 5

Original Poster
Rep: Reputation: 0
.......................

Last edited by winstonblue; 05-21-2007 at 02:06 PM.
 
Old 05-19-2007, 08:12 PM   #4
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
I am not 100% sure that these will work correctly on minix. But it's worth a shot. Simplicity at it's finest.

1)
find ./ -type f -name "*[kl]" -print

2)
who | awk '{print $1}' | sort | uniq


Edit: *nix does not have "folders" it has directories.
 
Old 05-19-2007, 08:55 PM   #5
winstonblue
LQ Newbie
 
Registered: May 2007
Posts: 5

Original Poster
Rep: Reputation: 0
thank you very much
i want to end at k or l before dot. i dont want to examine the extension


i've tried this

find . -name '*[a-zA-Z0-9][kl]' -print

if there is lol.k it wont be a problem
but if there is lol.apk it will print this and i dont want it.
Any ideas?
also i want my results in controlled way. i want every 5 results to press enter to print the next 5 ect.
Thanks for 2) man.

Last edited by winstonblue; 05-19-2007 at 09:03 PM.
 
Old 05-20-2007, 01:22 AM   #6
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
That gets a little bit more complicated (OK, a lot more complicated)... and there is an answer... but before I give this to you, I need to know this isn't homework.

The question just seems too contrived for me to assume it is something you need to so. Explain to me what you are doing, that you need to do this.
 
Old 05-20-2007, 01:41 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by frob23
2)
who | awk '{print $1}' | sort | uniq
Not lazy enough ;}

Code:
who | awk '{print $1}' | sort -u

Cheers,
Tink
 
Old 05-20-2007, 02:02 AM   #8
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
lol... you want to see code doing more work than it should? Here is my "solution" to his revised #1:

Code:
find ./ -type f -print | awk 'BEGIN{FS="."}{count=2;while($count){++count};count-=2};$count~/[kl]$/{print $0}' | more
I am putting it up because I am going to bed. It may be because it is 3am but I just couldn't get a regular expression which would match:
took.foo && fanny.pack.mp3

But not:
hello.pak || hill.of.beans

As a bit of explanation (for winstonblue)... because, if this is homework, he's going to understand the answer:

Uhm... forget it... it is too late for me to type it out. For explanation: man awk

Edit: and it pages at the defined page size... not 5 lines... if that is really required he can write his own readline loop in the shell to accomplish it.

Edit 2: This also works (in bash, sh, and probably ksh)
Code:
find ./ -type f -print | while read LINE; do if [ x`echo ${LINE%.*} | grep "[kl]$"` != "x" ]; then echo $LINE; fi; done
I do not know that it is much easier to understand... but it abuses the shell instead of my favorite whipping boy (awK).

Last edited by frob23; 05-20-2007 at 02:28 AM.
 
Old 05-20-2007, 09:27 AM   #9
winstonblue
LQ Newbie
 
Registered: May 2007
Posts: 5

Original Poster
Rep: Reputation: 0
it makes the right results but what is this exactrly doing to work it out?

find ./ -type f -print | while read LINE; do if [ x`echo ${LINE%.*} | grep "[kl]$"` != "x" ]; then echo $LINE; fi; done

Last edited by winstonblue; 05-21-2007 at 02:06 PM.
 
Old 05-20-2007, 12:31 PM   #10
frob23
Senior Member
 
Registered: Jan 2004
Location: Roughly 29.467N / 81.206W
Distribution: OpenBSD, Debian, FreeBSD
Posts: 1,450

Rep: Reputation: 48
Code:
     1  find ./ -type f -print | while read LINE;
     2  do
     3          if [ x`echo ${LINE%.*} | grep "[kl]$"` != "x" ]; then
     4                  echo $LINE;
     5          fi;
     6  done
To help me explain it, I have broken it up into multiple lines and numbered them. This is actually a very small bourne shell script. I gave it as one line to avoid even more confusion. I am going to use the numbers to help explain things. They are not part of the real thing and they are a little arbitrary... I could have numbered them differently if I had laid them out differently.

Line 1: find ./ -type f -print | while read LINE
This bit of code finds all the regular files under the current directory. It then pipes them (|) to a while loop... which stores each line in a variable called LINE. This essentially feeds the actual work part of the program.

Line 2: do
This is the start of our loop. We are going to do all the following steps to each line produced by find above.

Line 3a: `echo ${LINE%.*} | grep "[kl]$"`
The code ${LINE%.*} finds and removes the shortest suffix it can, matching the pattern ".*" which removes any extension. This is where the magic actually happens. The result of the first bit is fed into a grep to see if the end of the line ($) is a k or an l ([kl]).

Line 3b: if [ x` ... ` != "x" ]; then
The 3a bit leaves a string in the if test, if there was a match. So for example, "if [ xtook != x ]; then" would be the test being evaluated and would be true. If there was no match... it would be an empty string and x would equal x so the body of the if loop would not be executed. "!=" tests to ensure that the strings are not equal.

Line 4: echo $LINE;
If the above if test was true, we print out $LINE... which was the name of the file found by find.

Line 5: fi
This closes out if test.

Line 6: done
This signifies the end of our while loop that started with do above... well really started with the while code itself but structurally was wrapped with do and done.


I hope this helped make a little sense of it.
 
Old 05-20-2007, 06:16 PM   #11
winstonblue
LQ Newbie
 
Registered: May 2007
Posts: 5

Original Poster
Rep: Reputation: 0
wow you are the best. Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is minix Clarence27 Linux - Newbie 7 02-11-2007 04:54 PM
minix buffer computer Other *NIX 16 02-20-2006 08:48 AM
Minix 3 is out Ahmed Other *NIX 4 10-25-2005 02:27 AM
Minix darkRoom General 9 10-18-2005 06:49 PM
x windows on minix??? user222 Other *NIX 1 11-17-2004 06:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration