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 to create purchase order

2 Answers  


I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

0 Answers  


What does echo mean in scripting?

0 Answers  


Is shell scripting a programming language?

0 Answers  


What are the different commands available to check the disk usage?

0 Answers  






How to add some content in any file at some desired location without using VI or some other editor in UNIX

2 Answers  


How will you print the login names of all users on a system?

0 Answers  


How to set an array in linux?

0 Answers  


write a scwipt that a) takes exactly one argument, a directory name. b) if the number of argument is more or less than one,print a usage message c) if the argument is not adirectory, print another message d) for the given directory, print the five biggest files and the five files that were most recently modified. e) save the output to a file called q2output.

2 Answers  


Why should we use shell scripts?

0 Answers  


How can the contents of a file inside jar be read without extracting in a shell script?

0 Answers  


What is the best shell scripting language?

0 Answers  


Categories