I want to make a script that creates files in selected directory.
list is the list of names input by user when executing shell file
Code:
bash shell.sh file01 file02 file03
then "for" should create three files in pre-set directory under the names of file01, file02 and file03.
Code:
list=($1 $2 $3 $4)
for i in $list
do
echo "Created file: $list"
touch /home/paulius/Desktop/shell $list
done
All this code does is creates one file and echoes Created file: file01. And that is it. What is wrong in the code?
EDIT:
Also, reading the variables from file "list.txt" would be even better. How could I do that?
EDIT2:
Code:
#!/bin/bash/
if test -s /home/paulius/Desktop/shell/shell_testas/sarasas.txt
then
for line in $(cat sarasas.txt)
do
if test -d /home/paulius/Desktop/shell/shell_testas
then
echo "Created file: $line"
touch /home/paulius/Desktop/shell/shell_testas $line
else
echo "No such directory"
break
fi
done
else
echo "Empty list"
fi
Works great for me situation.