Reputation: 5
My script is:
#!/bin/bash
for n in {1..10}; do
echo $n
dd if=/dev/urandom bs=1 count=$(( RANDOM + 1024 )) > /testingscript/file${n}.txt
done
I would like it to create a file in the /testingscript directory with the name file'n'.txt, where n is the number of the file. Instead, I am getting this error:
1
./create.sh: line 5: /testingscript/file1.txt: No such file or directory
2
./create.sh: line 5: /testingscript/file2.txt: No such file or directory
3
./create.sh: line 5: /testingscript/file3.txt: No such file or directory
4
./create.sh: line 5: /testingscript/file4.txt: No such file or directory
5
./create.sh: line 5: /testingscript/file5.txt: No such file or directory
6
./create.sh: line 5: /testingscript/file6.txt: No such file or directory
7
./create.sh: line 5: /testingscript/file7.txt: No such file or directory
8
./create.sh: line 5: /testingscript/file8.txt: No such file or directory
9
./create.sh: line 5: /testingscript/file9.txt: No such file or directory
10
./create.sh: line 5: /testingscript/file10.txt: No such file or directory
What am I doing wrong causing my script to not write new files? I should add that this script worked perfectly as intended on my VM running Ubuntu 16.04. I am now attempting to run this on a physical computer running Ubuntu 18.04.
Upvotes: 0
Views: 371
Reputation: 678
There is no directory
/testingscript
If you want to create files in the current directories folder
yourCurrentDir/testingscript
You should remove the first "/" and use testingscript/file${n}.txt
#!/bin/bash
for n in {1..10}; do
echo $n
dd if=/dev/urandom bs=1 count=$(( RANDOM + 1024 )) > testingscript/file${n}.txt
done
To check if there is a directory /testingscript
ls / | grep testingscript
The expected output is
testingscript
Upvotes: 3