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
What are the different commands available to check the disk usage?
wats the deinitions for shell utility and filter?
What is a beat in a script?
How to get the 3rd element/column from each line from a file?
What is the purpose of scripting?
How do I set bash as default shell mac?
Why is shell scripting important?
What language is bash written in?
What is shift command in shell script?
What is bourne shell scripting?
What does egrep mean?
how to get part of string variable with echo command only?
Give some situations where typing error can destroy a program?
What shell is bin sh?
What are the advantages of shell script?