ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how can i create help function for my script?
i tried this function but when shell console is minimized text doesn't appear in a good format.
how can i create a well designed help message like manuals?
Code:
function helptext
{
# Function to display help message for program
local tab=$(echo -en "\t\t")
cat <<- -EOF-
${PROGNAME} ver. ${VERSION}
This is a program to backup and restore data files of system
and tables of xopensdb database.
$(usage)
-h, --help Display this help message and exit.
you can use ${PROGNAME} in expert or interactive mode. ${PROGNAME} without any input option brings up interactive mode, so you can follow wizards.
${PROGNAME} backup starts backup utility and ${PROGNAME} restore starts restore wizard.
User commands:
backup backup mode, using backup command you can creat backup archive from system files or database.
With no parameter after backup command, dummies mode starts, so you can use wizard.
restore for restoring data files of scada application or data tables in xopensdb.
some options can be used after related commands. restoring mode is necessary option for this command
User options:
-d Operate backup or restore functions on the database parameter files from xopensdb
-f Operate backup or restore functions on the data files in home directory of df8002 system (after -f you have to specify home directory of df8002)
-a Opreate backup and restore functions on both data files and database parameters.
-sync this option only can used by restore command. In synchronazation mode, some datas skipped during restoration process.
-all this option only can used by restore command. In this mode, all datas restored. Be carefull about inopportune use of this option
-h, --help Display this help message and exit.
-EOF-
}
Bash does not do re-sizeable text like man pages. You could write a man page for your script and have the script itself display that. There's a lot about writing man pages here.
If you want a really nice looking help you should look into man pages as catkin suggests. If you just want reasonable line breaking you can replace cat with fmt and put all paragraphs on a single line.
I use the help2man program to generate them. You just need to write functions for the two command-line options '--version' and '--help' which show the version and some help text.
You don't need to (and shouldn't) do any fancy formatting of the text, but use double spaces at the begiining of the help lines:
Code:
show_usage() {
echo " $0 [OPTIONS] FILE"
echo " --help show this help screen"
echo " --version show the version number and exit"
}
You may still need to fine tune it a little or adjust the formatting in the above function, but once you figure it out you have a formula for easily creating man-pages for any script without having to learn a lot of groff or using special man-page editors -which give varying results.
Thanks for your replies
But none of these solutions useful for me.
I can't surrender multiple files as a utility. I have bounded to deliver only one file to my boss. (one script file)
Thanks for your replies
But none of these solutions useful for me.
I can't surrender multiple files as a utility. I have bounded to deliver only one file to my boss. (one script file)
How about writing the script to write a man page in a temporary file, display it and then delete the temporary file?
Thanks for your replies
But none of these solutions useful for me.
I can't surrender multiple files as a utility. I have bounded to deliver only one file to my boss. (one script file)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.