LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 10-28-2014, 04:25 PM   #1
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Rep: Reputation: Disabled
Shell Scripting Arguments help needed bad


I've been trying to do arguments for the longest time and I just need a straight answer on how to apply them on scripts and how to run a specific argument for example this is what I have to do

Modify the script file now stored in your bin folder so that it accepts an arguement
The new arguement will be a path for a folder you want backed up
Your script will replace each instance of /var with that arguement
You should be able to run your script from anywhere in Linux and have it backup to a set location
Alter your filename so that your path becomes a part of it, along with the date


Just show how to do it and how to run that specific argument please. PS Im running on Linux Ubuntu I dont know if it makes a difference.
 
Old 10-28-2014, 04:33 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
If even after "the longest time" you still have no idea how to grab a command line argument from within a script, then I'm afraid nobody can help you. You need to put forth some effort of your own and show us where you're stuck in order to get any help. We won't do your homework for you.

http://www.linuxquestions.org/questi...27-4175523395/

And a simple Google search for "bash command line arguments" returns these handy references:
http://www.tldp.org/LDP/abs/html/
http://how-to.wikia.com/wiki/How_to_..._a_bash_script
http://linuxcommand.org/wss0130.php
http://linuxconfig.org/bash-scripting-tutorial
http://www.ibm.com/developerworks/library/l-bash2/
 
1 members found this post helpful.
Old 10-28-2014, 05:19 PM   #3
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Then teach me just show me some examples please.
 
Old 10-28-2014, 05:32 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
There are plenty of examples in the five links I just gave you, which I found with a 1 second Google search (along with hundreds more).

As I said before
Quote:
You need to put forth some effort of your own and show us where you're stuck in order to get any help.

http://www.linuxquestions.org/questi...27-4175523395/
 
Old 10-28-2014, 05:51 PM   #5
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Instead of the echo how do I put a command like do I just type it.
 
Old 10-28-2014, 05:53 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by ABCDblade View Post
Then teach me just show me some examples please.
If you have really been looking for the longest time and have not found this basic information, then you may well be unteachable...

On the other hand, since the question implies that this is one step in a series (i.e. "Modify the script file now stored in your bin folder..."), it seems to indicate that you may not have performed the previous steps which probably would have taught you how to perform this step...

Either of those behaviors are not beneficial for you, or those who might try to help you.

But, if you are really trying to learn how this works, a good place to begin (in addition to all the links provided by suicidalegroll) would be here: Bash Guide for Beginners.

For your specific needs, read down to Section 3.2.5 - Special parameters, and in particular, positional parameters.

For an example, say that you have a script named myscript, which takes a path argument, you would run it like this...
Code:
myscript /path/to/something
Inside the script, the path argument would be found in the first positional variable, so your script would look something like this:

Code:
#!/bin/bash

if [ "$1" != "" ]; then
   do_something_with $1
else
   print "No path provided..."
   exit 1;
fi
See what you can make from that beginning and let us know what you come up with. Good luck!

Last edited by astrogeek; 10-28-2014 at 05:56 PM.
 
1 members found this post helpful.
Old 10-28-2014, 05:56 PM   #7
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Still don't understand
 
Old 10-28-2014, 06:11 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Still not trying
 
Old 10-28-2014, 06:15 PM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by ABCDblade View Post
Still don't understand
That's equivalent to "doesn't work".
Please clarify what you are having trouble understanding.

and show us your work before we got involved.

Last edited by Habitual; 10-28-2014 at 06:16 PM.
 
Old 10-28-2014, 06:15 PM   #10
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
I am I have been trying for a month all those links you posted I have beem there they do not answer my question
 
Old 10-28-2014, 06:16 PM   #11
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Habitual Im having trouble on putting a argument inside a script I dont know the commands and how to run the arguments.
 
Old 10-28-2014, 06:22 PM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
If you honestly cannot find the solution from any of the links provided, my suggestion would be to quit this course as you are not suited.

As you have found, no one here is going to do the work for you, although in saying that I am not sure what else you would like from astrogeek's example.

You may also wish to go an re-read (as I assume you have already read them once) the LQ rules that states:
Quote:
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
 
Old 10-28-2014, 06:28 PM   #13
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
I understand about the whole not doing your homework. What I need is just examples of it just show me one example on amything but on the topic on how to use arguments. I aint asking for no answer but an example.
 
Old 10-28-2014, 06:49 PM   #14
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
As I asked once already, show us the script in your bin directory/"folder".

I'm sensing a pattern to this thread. But it could be just "me". I'm old and tired

Quote:
Originally Posted by ABCDblade View Post
Modify the script file now stored in your bin folder so that it accepts an arguement
Show us that script.

Here's a basic argument script:
Code:
#!/bin/bash
## Basic argument script 
## Habitual@LQRocks.
MINPARAMS=1

if [ $# -lt "$MINPARAMS" ]
then
  echo "Usage: This needs an argument"
fi
http://linuxconfig.org/bash-scriptin...he-bash-script

Last edited by Habitual; 10-28-2014 at 06:54 PM.
 
Old 10-28-2014, 07:07 PM   #15
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by ABCDblade View Post
What I need is just examples of it just show me one example on amything but on the topic on how to use arguments. I aint asking for no answer but an example.
Every single one of the links I provided has examples on using command line arguments in bash shell scripts, both how to pass it to the script as well as how to read it from inside the script.

Last edited by suicidaleggroll; 10-28-2014 at 07:08 PM.
 
  


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
Advice needed for moving away from shell scripting chicken76 Programming 24 10-24-2013 07:35 PM
[SOLVED] Shell Scripting: Scraping Public IP and Emailing - [: too many arguments zer0signal Programming 20 07-06-2011 08:28 AM
Shell scripting help needed burwood_301 Linux - Newbie 3 04-19-2010 02:00 PM
shell scripting - help needed jonhewer Linux - Newbie 54 09-09-2005 02:58 PM
Shell scripting and background processes - help needed. trafalgar Programming 3 06-08-2003 09:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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