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 |
Is shell scripting a language?
What are environment variables?
How to find all the files modified in less than 3 days and save the record in a text file?
how to print the matrix form of 2-d, 3-d arrays in unix c shell scripts ?
I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?
What is a shell script? Can you name some of its advantages?
What's the difference between scripting and coding?
What is shell scripting used for?
What is echo $shell?
What is path in shell script?
Create a bash shell script that reads a line from the user consisting of 5 words and then prints them out in reverse order. Name this script "reverse.sh"
determine the output of the following command: echo ${new:-variable}