write a shell script that accepts name from user and
creates a directory by the path name, then creates a text
file in that directory and stores in it, the data accepted
from user till STOP, displays the no. of characters stored
in the file.Program stops if directory name is null
Answer Posted / geichel
#!/bin/bash
echo -n "Enter directory name:"
read x
[[ ${x:='xX'} == 'xX' ]] && echo "error: No filename" &&
exit 0
mkdir --parents "/tmp/$x" 2> /dev/null
echo -n '' > "/tmp/$x/$x.txt"
echo "Enter text. Type 'STOP' on a line by itself to terminate."
while read y
do
[[ "$y" == "STOP" ]] && break;
echo "$y" >> /tmp/"$x"/$x.txt
done
a=$(wc -c "/tmp/$x/$x.txt" | cut -f1 -d' ')
echo
echo "file: /tmp/$x/$x.txt has $a characters"
exit 0;
| Is This Answer Correct ? | 2 Yes | 5 No |
Post New Answer View All Answers
Is bash an operating system?
c program to display the information of given file similar to givan by the unix or linux command ls -l
How to get the last line from a file using just the terminal?
What is the use of echo in shell script?
What is meant by dos operating system?
I have 2 files and I want to print the records which are common to both.
Given a file find the count of lines containing the word "abc".
How does path variable work?
What does $$ mean in shell script?
How do you know which shell I am using?
Is bash a shell script?
i have 2 tables 4 colums table 1 respective values a1 6, a2 8,a3 9,a4 14 & table 2 respective values a1 6, a2 8, a3 9, a4 12. if compare 2 tables 3 colums values same then 4th column values 1)Qes diff >5 then (5 * diff value ) 2)Qes diff <5 the 5 3)Qes diff 5 then 5 print respective values..
How to check if a directory exists?
What is c in shell script?
What is option in shell script?