create file in for loop.
I'm stuck and I've been searching and can't figure out how to do the script to this question.
Make a bash script that will use a for loop to create 130 test outputs called Outputs/txxx.out where xxx is the test number 1 to 130. Each .out file will have the contents: Test: xxx Date: current date |
Start by showing use your code so far and exactly what errors/msgs you get.
Also, bookmark/read http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
This is all I have.
Quote:
|
Just append the filename
Code:
for ((i = 0 ; i <= 130 ; i++)) # here you want <130 or you'll get 131 ie 0-130 inclusive 1. indent your code 2. 'touch' is redundant; the echo will create the file 3. '>' means output to file, overwriting what's there! '>>' means append. In fact, you could use append on both cmds; it also creates the file if not extant 4. why 'date'; that doesn't do anything ... see note 5 5. I think what you mean for the last 2 lines is Code:
echo "Date: $(date)" >>Outputs/t$i.out |
Thanks, I thought that appending with >> deleted the content of the file before appending.
Note: On the date part of the code i meant to write it like this Quote:
|
If your ultimate purpose is to create 130 files, ranging from 1 to 130, then the touch command can do the same without using a for loop or script, like this:
Code:
~$ cd Outputs |
All times are GMT -5. The time now is 10:20 PM. |