LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-27-2014, 12:49 AM   #16
jrosevear
LQ Newbie
 
Registered: Nov 2006
Distribution: Slackware
Posts: 29

Rep: Reputation: 14
Bash scripts and functions are helpful


This is an old thread, but I was happy to find it. Perhaps you came here needing a solution to a menuing problem like the one originally posted. I have (over many years) worked to find a solution to this same problem. I will share it with you.

I have found Bash scripts and functions to helpful in treating this common problem. Scripts and functions do things for you. They can use logic and variables. Scripts can do just about anything that you can do at the keyboard. Functions are handy for certain kinds of operations like changing environment variables or the current directory

For me the challenge was organizing my scripts and functions. I wrote a script called "menu" which is always in the PATH. When you run menu the list of scripts currently in the PATH and functions currently set are displayed by use of less. Next to each script or function is displayed a short description of how to use it. Some scripts/functions just run. Others need extra information, called arguments, to be listed after. This is just normal linux syntax.

I also wrote a script bound.f that sets a function called "bound" Function "bound" is always set. It takes an argument, $1. When you run "bound $1" then PATH is changed to include $1 in PATH and to run any function definitions found at $1, setting the functions in the current environment. It also unsets any functions that were previously set by use of bound and removes from PATH anything previously added by use of bound. Actually, there's more that I haven't explained.

If you're paying attention you will see the power and usefulness of this method. It is general purpose and flexible. Here is an example of its use:

pdata; not_host; r_dwa

I used this today. By a previous use of bound a function "pdata" had already been set. Using pdata invokes "bound $env_always/pindex" where env_always had already been defined. This use of bound sets function "not_host". Using not_host invokes "bound /mnt/joresorc/not_host". This use of bound puts script r_dwa in PATH. Using r_dwa displays password and login information I had previously put in file r_dwa.dat.

On one command line above I selected a collection of "pdata" scripts and functions, then used one of them called "not_host" which in turn selected a collection of scripts and functions, then used one of them called "r_dwa" which displayed the information I needed.

I could have run each of the three commands above separately:

pdata
not_host
r_dwa

After each of the above I could have used the "menu" command. I didn't, because I have the menus memorized. When I need some help, then I use them "menu" command.

I hope this helps those of you who have come to this thread. Good luck in your search for a good way to make menus.
 
  


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
Text-Based Linux williamjonah Linux - Software 7 08-29-2005 02:03 PM
why use text based Linux dcc Slackware 13 04-26-2005 11:23 AM
Any Text-Based Word Processors for Linux? linguae Linux - Software 10 07-06-2004 05:21 PM
how to browse from a text based linux daaku_n01 Linux - Newbie 2 05-20-2004 06:39 AM
RH Linux 8 pico ; text based login Pillay Linux - Newbie 2 11-02-2003 12:31 PM

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

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