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
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
I have to write Shells (Linux + Unix)for publishing packages and reports. Is it possible ? What are the differents executable programs ineed to call ?
Why are shell scripts used?
What is an inode block?
How would you compare the strings in a shell script?
What does the sh command do?
Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.
How to find all the files modified in less than 3 days and save the record in a text file?
What is wc in shell script?
What is echo $shell?
what is info area how many types?
What does $0 mean in shell script?
How to debug the problems encountered in the shell script/program?
Which scripting language is best for automation?
What does it mean by #!/Bin/sh or #!/Bin/bash at the beginning of every script?