LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Scripting Arguments help needed bad (https://www.linuxquestions.org/questions/linux-newbie-8/shell-scripting-arguments-help-needed-bad-4175523607/)

ABCDblade 10-28-2014 04:25 PM

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.

suicidaleggroll 10-28-2014 04:33 PM

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/

ABCDblade 10-28-2014 05:19 PM

Then teach me just show me some examples please.

suicidaleggroll 10-28-2014 05:32 PM

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/

ABCDblade 10-28-2014 05:51 PM

Instead of the echo how do I put a command like do I just type it.

astrogeek 10-28-2014 05:53 PM

Quote:

Originally Posted by ABCDblade (Post 5261003)
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!

ABCDblade 10-28-2014 05:56 PM

Still don't understand

grail 10-28-2014 06:11 PM

Still not trying

Habitual 10-28-2014 06:15 PM

Quote:

Originally Posted by ABCDblade (Post 5261018)
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.

ABCDblade 10-28-2014 06:15 PM

I am I have been trying for a month all those links you posted I have beem there they do not answer my question

ABCDblade 10-28-2014 06:16 PM

Habitual Im having trouble on putting a argument inside a script I dont know the commands and how to run the arguments.

grail 10-28-2014 06:22 PM

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.

ABCDblade 10-28-2014 06:28 PM

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.

Habitual 10-28-2014 06:49 PM

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 (Post 5260981)
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

suicidaleggroll 10-28-2014 07:07 PM

Quote:

Originally Posted by ABCDblade (Post 5261038)
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.


All times are GMT -5. The time now is 12:30 PM.