Do not use on any
shared computer
August 29, 2008 02:59pm pdt
 
[x]
Attachment Details

Creating a bash script which accepts parameters

Hi guys hope u r well and can help.

Im trying to build a perl (OR bash) script that will help me automate the process of creating new files based on what I have in the perl (or bash)script.

-------------------------
CURRENT METHOD:
-------------------------
Here is what Im currently doing (which I wish to change by building a bash script):

Im manually doing the following each time I need to create a new file.

cp /var/www/html/simeswiki/templates/menu1.php /var/www/html/simeswiki/menu1_<name>.php
cp /var/www/html/simeswiki/templates/menu2.php /var/www/html/simeswiki/menu2_<name>.php
cp /var/www/html/simeswiki/templates/menu3.php /var/www/html/simeswiki/menu3_<name>.php
cp /var/www/html/simeswiki/templates/menu4.php /var/www/html/simeswiki/menu4_<name>.php
cp /var/www/html/simeswiki/templates/menu5.php /var/www/html/simeswiki/menu5_<name>.php


-------------------------
GOAL/s:
-------------------------

- Create a perl (or bash) script that:
a) Contains the full path to the menuX.php files
b) Upon execution,
(i) Will prompt for a destination filename for each copy command executed in the bash script
(ii) Will not require the full path and filename for the newly created filename for each copy command executed.

So, for example, if the script was called createfile.sh,

(Comments are in  <  >, and defines if it is user entered of script)

If i run createfile.sh, it will do something like the following..........

createfile.sh      <Run script>
Enter New Filename based on menu1.php....  <Script>
menu1_mynewfile.php        <User>
Enter New Filename based on menu2.php....  <Script>
menu2_mynewfile.php        <User>
Enter New Filename based on menu3.php....  <Script>
menu3_mynewfile.php        <User>
Enter New Filename based on menu4.php....  <Script>
menu4_mynewfile.php        <User>
Enter New Filename based on menu5.php....  <Script>
menu5_mynewfile.php        <User>

If the user does not enter a filename for each response from the script, the script will prompt for a filename PRIOR to continuing on, and also let the user know if that file already exists and ask if they wish to overwrite, then continue on.

The "Template" files eg. menu1.php, menu2.php, menu3.php, menu4.php and menu5.php are ALL located in the following location...
/var/www/html/simeswiki/templates

When prompted by the script to ask for a filename, I only want to have to enter the FILENAME ONLY, not the full path.
Also, the new files are ALL to be saved into the following location:

/var/www/html/simeswiki


I hope this makes sense.

Any help greatly appreciated.
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: Simon336697
Solution Provided By: ozo
Participating Experts: 2
Solution Grade: A
Views: 20
Translate:
Loading Advertisement...
 
[+][-]Assisted Solution by Adam314

Rank: Genius

Assisted Solution by Adam314:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ozo

Rank: Genius

Expert Comment by ozo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Simon336697
Author Comment by Simon336697:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by ozo

Rank: Genius

Accepted Solution by ozo:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by Simon336697
Author Comment by Simon336697:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628