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

What is eval in shell script?

0 Answers  


What are the 3 standard streams in linux?

0 Answers  


What is the meaning of $1 in shell script?

0 Answers  


Is it possible to substitute "ls" command in the place of "echo" command?

0 Answers  


Write down the syntax of "for " loop

0 Answers  






I want to read all input to the command from file1 direct all output to file2 and error to file 3, how can I achieve this?

1 Answers  


What are script files?

0 Answers  


What is Path variable?What is its use?

1 Answers  


determine the output of the following command: echo ${new:-variable}

0 Answers  


Please give me example of " at command , contrab command " how to use

0 Answers  


How to print pid of the current shell?

0 Answers  


How does path variable work?

0 Answers  


Categories