LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2010, 10:35 AM   #1
kmbl
LQ Newbie
 
Registered: Nov 2010
Posts: 2

Rep: Reputation: 0
Cool Bash Commands


This is the following exercise:
Adapt this to write a script storedList that takes two command line parameters. The first parameter is the name of a directory, the second parameter is the name of a directory should be store i.e
# ./storeList.sh /etc etcFilesList

How can you refer to the variables that represent the words passed in on the command line?

My Script's file:
#!/bin/bash
if test $# == 2
then
ls $1 > S2.txt
else
echo “Please enter 2 command line parameters”
fi


I'm using
#chmod u+x storeList.sh
#./storeList.sh
But I don't know what kind of commands should I use for the next line.
!!! Please, can anyone help me!

Last edited by kmbl; 11-28-2010 at 04:03 PM.
 
Old 11-28-2010, 10:57 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I'm curious about the bad writing in your homework assignment:

Quote:
Originally Posted by kmbl View Post
This is the following exercise:
...
the second parameter is the name of a directory should be store
Did you do a sloppy job of retyping it into the forum? Or it was assigned in some other language and you didn't translate to English very well? Or the original assignment was that garbled?

Quote:
How can you refer to hte variables that represent the words passed in on the command line?
Where did your sample script come from? Did you write it?

You seem to be successfully using $# for the count of words on the command line and $1 for the first word (after the command itself). I assume you could have used $2 for the second word if you had wanted to and/or typed carefully.

So what is your question about "variables"?

Quote:
What kind of commands should I use in the terminal console?
I used #chmod u+x storeList.sh
#./storeList.sh
In the assignment itself that you quoted, you had
Quote:
i.e
# ./storeList.sh /etc etcFilesList
Did you not understand that is an example of the terminal command you would use to run your script?

You seem to have included almost all the answers to your possible questions in your own post. So it is very hard for me to guess what parts you don't understand.

BTW, my complaints about the quality of your typing and/or translation in the posting of your original assignment do not imply that a better job of quoting the original assignment would be acceptable. You should give us a better idea of which specific aspects of the assignment you understand or fail to understand. You should not expect anyone to do the assignment for you, just to explain specific aspects of it that you don't yet understand.

Last edited by johnsfine; 11-28-2010 at 11:06 AM.
 
Old 11-28-2010, 11:24 AM   #3
kmbl
LQ Newbie
 
Registered: Nov 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Oh,sorry I wrote it wrong.
This is the correct exercise.

Adapt this to write a script storedList that takes two command line parameters. The first parameter is the name of a directory, the second parameter is where the list of files in that directory should be store. i.e.: ./storeList.sh /etc etcFilesList
How can you refer to the variables that represent the words passed in on the command line?

This is my script solution:

if test $# == 2
then
ls $1 > $2.txt
else
echo “Please enter 2 command line parameters”
fi

I used in the terminal console this commands:
#chmod u+x storeList.sh
#./storeList.sh

But I don't know what kind of commands should I use for the next line.

I hope you can understand now!
 
Old 11-28-2010, 12:11 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Use

Code:
./storeList.sh /etc etcFilesList
 
1 members found this post helpful.
Old 11-28-2010, 06:22 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I am with H and john in not understanding exactly what your issue is?

Yes your second post has made more sense with the restated question typed in properly, but again you seem to not be following what you have written.

As H has posted, your own question has the how part of what you are to type at the command line when executing the script.
Quote:
But I don't know what kind of commands should I use for the next line.
Maybe you could write a little more as to which 'next line' you are talking about?

If you can explain what the 'next line' is you are referring to then we may be able to tell you what command you are looking for?
 
  


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
Running bash but common bash commands not working michellepace Linux - Newbie 11 07-17-2010 09:19 AM
Few commands in bash c4nk Linux - General 10 12-18-2006 02:19 AM
bash commands davatar Slackware 2 04-06-2005 03:05 AM
bash commands Obie Linux - Security 4 08-15-2004 02:42 PM
Bash commands wprescott Linux - Distributions 6 04-27-2002 02:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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