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 / 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 |
How to debug the problems encountered in the shell script/program?
How to declare functions in unix shell script?
Why do we write bin bash in shell scripts?
Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each column. Pretend that ls does not have multicolumn output.
How do I open the shell in cmd?
What are the different communication commands available in the shell?
What does $@ mean in shell?
What is a shell script in windows?
What is Linux language details
I have 2 files and I want to print the records which are common to both.
Is SSO and SSL support BOXI?
How can I set the default rwx permission to all users on every file which is created in the current shell?