ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ok, yes, I'm a newb, but at least I'm trying to learn bash shell scripting. 8^)
From what I've learned about for loops, it seems like the following should work:
for i in $(ls ~) do;
> echo 'Pristine text for file ' > $i
Before I can continue the script, I get an error after hitting Enter (after $i):
bash: syntax error near unexpected token `echo'
I've tried using double quotes around the statement after echo, but I get the same results. The reason I'm doing all of this to test subversion version control, so I've made file1 file2 and so on for a total of 5 files. Since I'm still new at bash shell scripting, I'm not sure how else to have each file contain "Pristine text for file1", then for file2: "Pristine text for file2" and so on. The thought was, after each file gets the first echo statement, I could go back through each file and append (>>) the number to the end of each, containing 1, 2 and so on.
the semicolon should be before the "do", not after it.
Eg
Code:
for i in ~/* ; do
#echo 'Foo bar' > $i
done
Note two other things:
1. Better to use shell globbing instead of ls.
2. I don't really understand what you are trying to achieve, but not that you will be replacing every file in your home directory with this single line of text. So, running the above is VERY DANGEROUS and almost certainly not what you want to do (it is for this reason I put a comment before the echo).
Thanks for your reply. I'm testing subversion so I've created a couple of directores, d1 and d2. Within them, I have file1 through file5. I wanted to quickly generate text specific to each file - hence the script requirement. Obviously, if there's a better way to achieve this than what I'm doing, I'd definitely appreciate the help.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.