LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help new to Linux!!! (https://www.linuxquestions.org/questions/linux-newbie-8/help-new-to-linux-558480/)

HollywoodBashMan 06-01-2007 09:49 PM

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!

jtshaw 06-01-2007 10:22 PM

This is all you need...

Code:

#!/bin/bash
ls > partaTest.txt


HollywoodBashMan 06-01-2007 10:27 PM

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!!

jtshaw 06-01-2007 11:25 PM

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 >.

jstephens84 06-01-2007 11:33 PM

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.


All times are GMT -5. The time now is 06:31 PM.