LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-13-2014, 07:18 PM   #1
pump1t
LQ Newbie
 
Registered: Aug 2014
Posts: 5

Rep: Reputation: Disabled
Need help with shell scripting


Hello guys,

Ive just started using shell scripting again after a long time. just hoping you could help on this.

I'm trying to create a script using a menu with multiple options.
===================
Enter company ID:

echo "[1] HR21"
echo "[2] c21connect"
echo "[3] MHR21"
Select all products that applies:
===================
it will then create a conf using the company Id ,eg AAA_conf.

I have a template file for each product like:
temp.txt:
#BEGIN C21CONNECT
location /c21p/ {
(commads here)
}
#END C21CONNECT

This temp.txt will then be embedded to the specific area in the AAA_conf file
 
Old 08-13-2014, 11:49 PM   #2
notKlaatu
Member
 
Registered: Sep 2010
Location: Wellington, New Zealand
Distribution: Slackware
Posts: 896

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
I think there might be an argument here that it would be more unix-y if you skipped the menu and just made the input go something like this:

Code:
configurator.sh --hr21 --c21connect --mhr21 Acme
But obviously that's up to you. Even so, that's the example I'm going to provide and it should give you a rough idea how to parse the info:

Code:
#!/bin/bash

while [ True ]; do
if [ "$1" = "--help" -o "$1" = "-h" ]; then
echo " "
echo "configurator.sh [--mhr21|--c21connect|--hr21] company"
echo " "
exit
elif [ "$1" = "--mhr21" -o "$1" = "-m" ]; then
ITEM[1]='mhr21'
shift 1
elif [ "$1" = "--c21connect" -o "$1" = "-c" ]; then
ITEM[2]='c21connect'
shift 1
elif [ "$1" = "--hr21" -o "$1" = "-r" ]; then
ITEM[3]='hr21'
shift 1
else
break
fi
done

ITEM[4]=$1

#debugging
echo ${ITEM[1]}
echo ${ITEM[2]}
echo ${ITEM[3]}
echo ${ITEM[4]}

# create conf file
touch ${ITEM[4]}.conf
echo "#BEGIN C21CONNECT" >> ${ITEM[4]}.conf
echo "location /c21p/ {" >> ${ITEM[4]}.conf
echo  ${ITEM[1]}  ${ITEM[2]} ${ITEM[3]} >> ${ITEM[4]}.conf
echo "}" >> ${ITEM[4]}.conf

echo "all done i think"
Hope that helps.
 
Old 08-14-2014, 02:29 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
probably you can try the built-in select command (of bash). http://www.softpanorama.org/Scriptin...atements.shtml
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
LXer: Shell Scripting: Really Programming The Shell LXer Syndicated Linux News 0 02-28-2014 03:40 PM
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-13-2013 12:20 AM
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM


All times are GMT -5. The time now is 10:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration