LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-16-2013, 09:11 PM   #1
v3ct0r
Member
 
Registered: Jun 2013
Location: China
Distribution: Archlinux
Posts: 67

Rep: Reputation: Disabled
Shell wildcard for C program


I'm reading GNU sort recently, and it's implementation is almost like this
Click image for larger version

Name:	sort diagram.png
Views:	32
Size:	25.9 KB
ID:	14235

It's amazing that the sort program running so fast, cuz gnu sort contains like 20+ structure and alot of macros and so on, almost drive me crazy!!!

okay its not what I'm here, this is why I'm here.
Still I havent figure out that how to make
Code:
$ sort *
work? I didnt finish read everything of sort, so maybe gnu sort is be able to handle this situation, or it's the job of shell?
I'm trying to clone a simple edition or gnu sort for practice of writing a real program
 
Old 12-16-2013, 09:46 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by xeechou View Post
Still I havent figure out that how to make
Code:
$ sort *
work? I didnt finish read everything of sort, so maybe gnu sort is be able to handle this situation, or it's the job of shell?
I'm trying to clone a simple edition or gnu sort for practice of writing a real program
sort * will take the combined content of all files in the current directory (ecxept those whose name starts with a dot), sort it and write the result to standard output. If some of the files are binaries, the output will look funny, and your terminal may switch to an Amharic font.
Nothing particular is needed to make this work, just type it and enjoy.

Or did you have something else in mind? It's not quite clear to me what you want.
 
Old 12-17-2013, 12:31 AM   #3
v3ct0r
Member
 
Registered: Jun 2013
Location: China
Distribution: Archlinux
Posts: 67

Original Poster
Rep: Reputation: Disabled
Cool

Quote:
Originally Posted by berndbausch View Post
sort * will take the combined content of all files in the current directory (ecxept those whose name starts with a dot), sort it and write the result to standard output. If some of the files are binaries, the output will look funny, and your terminal may switch to an Amharic font.
Nothing particular is needed to make this work, just type it and enjoy.

Or did you have something else in mind? It's not quite clear to me what you want.
Well, I mean I'm cloning GNU sort program and I wanna know how to make "sort *" works for my sort program...
 
Old 12-17-2013, 01:13 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by xeechou View Post
Well, I mean I'm cloning GNU sort program and I wanna know how to make "sort *" works for my sort program...
Your clone needs to take an unlimited number of filename parameters. When you run clone *, the shell will expand the asterisk to the list of files in the current directory, and your clone will have to process all files.

There is a library routine named getopt that will help you with this task.
 
Old 12-17-2013, 08:49 PM   #5
padeen
Member
 
Registered: Sep 2009
Location: Perth, W.A.
Distribution: Slackware, Debian, Gentoo, FreeBSD, OpenBSD
Posts: 208

Rep: Reputation: 41
It's still not clear what you want.

The shell will pass in the list of all files in the current directory. That has nothing to do with your program; by the time your program has been loaded, initialised and set to run, argv is pointing to the start of the char array of list of files.

I can't help you on the method GNU sort uses to speed up its sort as I don't know anything about it.
 
  


Reply

Tags
shell, sorting



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
How do I pass wildcard as an argument to a shell script? Jykke Programming 8 03-09-2013 10:33 AM
if-then statement and wildcard: shell script Cyberman Programming 7 12-27-2009 07:49 AM
running a shell script which invokes another shell program!!! raghu123 Programming 1 08-04-2008 09:10 AM
HELP!! I need to program a shell pleowulf Programming 2 02-11-2005 01:12 PM
Shell Program Veteq Programming 12 08-18-2004 07:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:30 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