LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2009, 07:16 AM   #1
a.toraby
Member
 
Registered: Sep 2006
Location: tehran
Distribution: open suse & open solaris
Posts: 102

Rep: Reputation: 15
Question how can i create manual for my script?


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-
}
 
Old 11-17-2009, 08:01 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 11-17-2009, 08:52 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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.
 
1 members found this post helpful.
Old 11-17-2009, 11:21 AM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
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.
 
Old 11-21-2009, 06:42 AM   #5
a.toraby
Member
 
Registered: Sep 2006
Location: tehran
Distribution: open suse & open solaris
Posts: 102

Original Poster
Rep: Reputation: 15
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)
 
Old 11-21-2009, 07:02 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by a.toraby View Post
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?
 
Old 11-21-2009, 09:05 AM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by a.toraby View Post
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)
My solution doesn't need extra files.
 
1 members found this post helpful.
Old 11-21-2009, 10:04 AM   #8
a.toraby
Member
 
Registered: Sep 2006
Location: tehran
Distribution: open suse & open solaris
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ntubski View Post
My solution doesn't need extra files.
Oh, really?
Does fmt works like cat? So, I'll try it.
 
Old 11-26-2009, 06:48 AM   #9
a.toraby
Member
 
Registered: Sep 2006
Location: tehran
Distribution: open suse & open solaris
Posts: 102

Original Poster
Rep: Reputation: 15
I just replaced cat with fmt and it works fine.

Last edited by a.toraby; 11-26-2009 at 06:50 AM.
 
  


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
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 08:15 PM
How to create a Create script "easier"? lorio Linux - Newbie 6 10-10-2006 06:05 PM
Need help to create a script barneyt Programming 2 08-18-2006 04:11 PM
Trying To Create An Install Manual/Tutorial eder_michael11 Linux - General 2 01-25-2006 12:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:01 AM.

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