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

Hi, I want to practise Unix korn shell scripting which i learnt 2 yr bfr. plz suggest software i can use to practise.

1 Answers  


is there any command to find user password?

4 Answers  


What is batch file programming?

0 Answers  


How to print all array elements and their respective indexes?

0 Answers  


What is sh in shell script?

0 Answers  






How do I run a .sh file?

0 Answers  


I want to connect to a remote server and execute some commands, how can I achieve this?

0 Answers  


What are the different shells available?

3 Answers  


What is k shell?

0 Answers  


Write a shell script to looking at the log file to see if the test has passed or not

2 Answers   TCS,


Is shell a scripting language?

0 Answers  


What is another name for a bash shell script that you might see?

0 Answers  


Categories