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



write a shell script that accepts name from user and creates a directory by the path name, then cr..

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

Post New Answer

More Shell Script Interview Questions

How will you connect to a database server from linux?

0 Answers  


How do you find out What is your shell?

0 Answers  


what is tickets $ what low,medium,high priorite pls define time also

0 Answers  


what is info area how many types?

0 Answers  


What is sed in shell script?

0 Answers  


Is shell and terminal the same?

0 Answers  


In a single command how do you run the previous command in the command prompt.

5 Answers  


What is a command line shell?

0 Answers  


What is the syntax of while loop in shell scripting?

0 Answers  


In which variable prompt value is stored?

2 Answers  


How many prompts are available in a UNIX system?

1 Answers  


why did you apply to shell

3 Answers   Shell,


Categories