LinuxQuestions.org
Register a domain and help support LQ
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 06-01-2007, 10:49 PM   #1
HollywoodBashMan
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Rep: Reputation: 0
Help new to Linux!!!


Hey everyone!!

I am having a problem creating a bash script that will create a text file and then will take the contents of the current working directory and sent it to the text file.

Here is what I have so far:

#!/bin/bash

#Create the Required Text File:

cat > /partaTest.txt << EOF

#List Files in Text File:

ls >> partaTest.txt

EOF

Any suggestions? Thanks!
 
Old 06-01-2007, 11:22 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
This is all you need...

Code:
#!/bin/bash
ls > partaTest.txt
 
Old 06-01-2007, 11:27 PM   #3
HollywoodBashMan
LQ Newbie
 
Registered: Jun 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Look's to easy

So the "ls" command will not only print the working directory to the file but also creates it? I have been going crazy thinking there should be more code. I guess its just a simple script.

Thanks for your help!!
 
Old 06-02-2007, 12:25 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
The ls command isn't actually creating the file... but ya, it is that simple.

If you want to append to the file instead of overwrite use the >> instead of the >.
 
Old 06-02-2007, 12:33 AM   #5
jstephens84
Senior Member
 
Registered: Sep 2004
Location: Nashville
Distribution: Manjaro, RHEL, CentOS
Posts: 2,098

Rep: Reputation: 102Reputation: 102
For a great beginners guide on bash scripting use this site. http://tldp.org/LDP/Bash-Beginners-G...tml/index.html

Also a good book from amazon is
http://www.amazon.com/Automating-Lin...0758526&sr=8-3

The ls command is listing the information but the file is created when you use the redirect symbol > to output the results of ls to the partaTest.txt file.
 
  


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




All times are GMT -5. The time now is 09:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration