
How do I write a full-screen bash shell script?
Dear Dave: I am trying to write a full-screen utility that
displays the permissions of a directory and all the
directories in the directory's path. It should also show
other information about the directories, as the cursor
is moved up and down the list of directory names.
Can you offer me some pointers to get me started?
Well, first off, this kinda seems like it might be a homework assignment from a class that this chap is taking, so I'm not going to just write a script and post it. In fact, as a teacher, I have to say that I'm not in favor of people finding shortcuts to solve their programming assignment projects. If you're stuck on an assignment, your obligation is to ask the instructor for help or pointers, not to search the Internet for people you can hoodwink into writing your assignments. However, I could be wrong. :-) And in any case, I also remember that when I was an undergraduate, I got in trouble for referencing Don Knuth's wonderful Art of Computer Programming: Volume 1, Fundamental Algorithms book when we were supposed to ascertain which algorithm would produce an optimal sort for a specific type of unsorted input. Plus, it's an interesting question! So, yeah, I won't write the program for you, dear reader, but I will offer you some hints regarding what direction you can take to accomplish this task. First off, to gain rudimentary cursor control within a shell script, you'll want to use tput (you can read the tput man page to learn more) with friendly and mnemonic invocations like "tput cup 0 0", which moves the cursor to the top left corner, and "cols="$(tput cols)" to store the number of columns on the screen in a variable. It's not easy, as you can see, but you can definitely write a script that has complete control over the screen. However, if I were trying something like that, I think I'd just move right to curses and write the program in C, not as a shell script. It would doubtless save your sanity. (learn more about curses by reading the curses man page). You also have a bit of a challenge with accepting input from the keyboard, so you'll want to look at the specific settings to stty and then use a read statement within some sort of processing loop. Finally, in terms of ascertaining more information about a file or directory within a shell script, that's something I cover in detail within my popular book Wicked Cool Shell Scripts, which I'll recommend you pick up and read through. You can start by recognizing that you can invoke ls with a variety of different parameters, then parse and separate out the resultant parameters into different variables, then output those variables as you desire. You can also recursively navigate a directory tree with ls or its power nephew find. Good luck with this project and let me know how it all comes out!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Shell Script Programming
(Article 3782)
Tagged: Previous: How do I disable a CSS anchor hover? Next: How can I secure / encrypt folders on my Mac's USB flash drive? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.
Rather amazingly, there are no comments on this article yet.
I have a lot to say, but ...
I do have a comment, now that you mention it!
|
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|