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


Please Help Members By Posting Answers For Below Questions

What are the different commands available to check the disk usage?

489


wats the deinitions for shell utility and filter?

1837


What is a beat in a script?

536


How to get the 3rd element/column from each line from a file?

683


What is the purpose of scripting?

573






How do I set bash as default shell mac?

552


Why is shell scripting important?

570


What language is bash written in?

557


What is shift command in shell script?

521


What is bourne shell scripting?

530


What does egrep mean?

568


how to get part of string variable with echo command only?

586


Give some situations where typing error can destroy a program?

722


What shell is bin sh?

530


What are the advantages of shell script?

517