Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com

2559


I have to write Shells (Linux + Unix)for publishing packages and reports. Is it possible ? What are the differents executable programs ineed to call ?

2161


Why are shell scripts used?

1068


What is an inode block?

1044


How would you compare the strings in a shell script?

969


What does the sh command do?

1072


Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.

1144


How to find all the files modified in less than 3 days and save the record in a text file?

1051


What is wc in shell script?

974


What is echo $shell?

1078


what is info area how many types?

2755


What does $0 mean in shell script?

992


How to debug the problems encountered in the shell script/program?

1131


Which scripting language is best for automation?

952


What does it mean by #!/Bin/sh or #!/Bin/bash at the beginning of every script?

1054