*
The moose likes Linux / UNIX and the fly likes creating a script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "creating a script" Watch "creating a script" New topic
Author

creating a script

Zachary Smith
Greenhorn

Joined: Feb 17, 2011
Posts: 3
I've been given the task of creating a shell script and I am in over my head...

I need to:
Create a fully commented shell script which expects two arguments. a list of file names and 2) a directory. the script should also be able to accomplish tasks
like, check to see if there are tow parameters, check to see if the second parameter is an existing directory, check to see if the directory is writeable, use a loop, and check to see if the file exists in the home directory..

I doubt anyone can fully help me but I thought I would try

Thanks!
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Is this a homework assignment?

What specific questions do you have? How far did you get?


http://home.arcor.de/hirnstrom/bewerbung
Zachary Smith
Greenhorn

Joined: Feb 17, 2011
Posts: 3
Hey,

Yes it is.

So far I have just created a sub directory and began to make the .sh. I really just need help getting started. I don't understand what the "two arguments" are and how to do that... I'm a total rookie..

Thanks !

Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Did you ever start a program/command from the command line (shell, terminal)?

If you perform a copy, you call a program with 2 parameters, the source and the target:


a.txt is the first and b.txt the second parameter.

In a java-Program you get parameters with 'args':


'args' is of course a random name, just conventional named 'args'.

You ask the array for its length and iterate over the content if you need to. In the shell, the arguments are $1, $2, $... and $# is the number of arguments; a starting point:

Here is an in deep guide to bash-scripting: http://tldp.org/LDP/abs/html/
Feel free if you still have questions, but try for yourself, read your material, do your etudes.
Zachary Smith
Greenhorn

Joined: Feb 17, 2011
Posts: 3
Hey thanks so much,

So how exactly do I apply that to listing a file and a directory??

Thanks for the link
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

How do you list a directory in the shell?
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Here is - maybe more appropriate - a beginners guide: http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ and a command list: http://ss64.com/bash/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a script