Results 1 to 10 of 14
Hi to all.I need a shell script that will save in a file each line I write and then exits,while my file will be stored in my home dir.I have ...
- 07-03-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Shell Script help..
Hi to all.I need a shell script that will save in a file each line I write and then exits,while my file will be stored in my home dir.I have created something,but I must use Ctrl+C to exit.Here is my code:
This script also counts the number of lines of my text.I could your help...Code:#!/bin/bash read -p "give the name of the file: " NAME echo "Write your text" echo "press Ctrl+C to save and exit" i=1 while [ true ] do echo -n "$i " read line echo $line>>$NAME i=$((i+1)) done
- 07-03-2008 #2
- 07-03-2008 #3Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
well,I know this but when I tried to use while with an escape character(ex. press 000 to exit) in the file created there was also a line with the sequence 000.
- 07-03-2008 #4
how do you wanna stop the input(i mean there must be a way to tell the shell that you are done typing).
you can use here-documents(google for it in case) so that you give a special word to tell the shell that you are done typing the file content.
for example
would let you create a file called my_file then it puts everything you type in till you give it the word done.Code:cat >my_file <<done
Linux and me it's a love story
- 07-03-2008 #5Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Yes.I want to give a special word or symbol so that the input will stop and the word given won't be saved in my file.
- 07-03-2008 #6
so you can go for a here-document.
some googling and you are on track.Linux and me it's a love story
- 07-03-2008 #7Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
Thanks...it seems I'm finally on track...
- 07-03-2008 #8Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
On the contrary it seems I'm not on track as what I want is to input the text via the terminal.Any ideas..?
- 07-03-2008 #9
lol.
what do you mean by input text via the terminal?Linux and me it's a love story
- 07-03-2008 #10Just Joined!
- Join Date
- Jun 2008
- Posts
- 25
I don't want to write a script that will redirect a text file to another file.I want a script that after the execution will ask for my input and it will save it to a file.What I really want is to find how I can use an escape character when I won't want to write anymore and this character won't be saved in my file.


Reply With Quote