This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating a script

 
Zachary Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a homework assignment?

What specific questions do you have? How far did you get?
 
Zachary Smith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you list a directory in the shell?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic