LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 05: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, 05:33 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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, 06: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, 06:32 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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, 06: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, 06:53 PM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998
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 06:56 PM.
 
1 members found this post helpful.
Old 10-28-2014, 06:56 PM   #7
ABCDblade
LQ Newbie
 
Registered: Oct 2014
Posts: 7

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

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Still not trying
 
Old 10-28-2014, 07:15 PM   #9
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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 07:16 PM.
 
Old 10-28-2014, 07: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, 07: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, 07:22 PM   #12
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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, 07: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, 07:49 PM   #14
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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 07:54 PM.
 
Old 10-28-2014, 08:07 PM   #15
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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 08:08 PM.
 
  


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


All times are GMT -5. The time now is 10:13 PM.

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