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 it possible to substitute "ls" command in the place of "echo" command?
What is shell environment?
What is a boot block?
How do I run a bin bash script?
How to open a read-only file in the shell?
c program to implement unix/linux command to block the signal ctrl-c and ctrl-\ signal during the execution ls -l|wc -l
What is the command to find out today's date?
How do I run a script from command prompt?
Write down the syntax for all the loops in shell scripting.
What are the different commands available to check the disk usage?
How to print the first array element?
What is a shell in operating system?
Write a script to print the first 10 elements of fibonacci series.
Is shell scripting a programming language?
What shell is bin sh?