07-17-2007
Simple loop query
Hi All
Just started with shell scripts and am stumped by, what is to most of you no doubt, a simple issue.
All I'm trying to do is prompt a user for input and writing to a log file. If the user types the word 'stop', then the program should halt. If the word typed is 'clear', then the log file should be cleared.
Starting simply(!), all I've got so far is:
LOGDIR=/some/dir/
TARGETFILE="whatever"
ans="abc"
while [ ${ans} != "stop" }
do
echo "Enter text:"
read ${ans}
echo ${ans} >>${LOGDIR}/${TARGETFILE}
done
All that happens is the original value of "abc" is written to the log. Obviously the variable isn't being overwritten by the user input. Can anyone help with basic help for a newbie?
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
hi,
i would like to replace a string in a series of files with another string, without outputting to new files. is this possible?
i've tried using sed, and started by trying to alter the contents of one file...
sed 's/string1/string2/g' file.txt
but while this does the replacement on... (2 Replies)
Discussion started by: schmark
2 Replies
2. Shell Programming and Scripting
I want to write a script to go to particular path in file and run shell script from there.
what will be shell script for the same. (2 Replies)
Discussion started by: shekhar_ssm
2 Replies
3. Shell Programming and Scripting
Dear,
I have a alarm text file, containing minor and major alarms, i am intrested in Mojor alarm with its alarm header and next four lines in seperate file....
Can anybody help me with this below is the alarm file output.
:SEV="MAJOR":
Object-Instance %
unit-type % bts nbr % 25
... (5 Replies)
Discussion started by: Danish Shakil
5 Replies
4. Shell Programming and Scripting
Filename.txt
My First Line
My Second Line
::::While Loop:::
Program:
while read line
do
echo "$line"
done < Filename.txt
output:
My First Line
My Second Line
Is it possible to use for loop to get the same output.
I have tried executing below code but i get every word of my file... (8 Replies)
Discussion started by: pinga123
8 Replies
5. Programming
Given the following code inside the function ext3_write_super():
(It's there in Linux kernel 2.6.27.59)
static void ext3_write_super (struct super_block * sb)
{
if (mutex_trylock(&sb->s_lock) != 0)
BUG();
sb->s_dirt = 0;
}
The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies
6. Shell Programming and Scripting
Hi friends,
One of my shell program(test.ksh) contains the following if loop.Can anyone please explain me how this loop will work
The shell script will be executed as test.ksh -d all
The value of variables are
user=all
opt=-d
if &&
then
&& _del_all_w=1 || _group="${1}"... (1 Reply)
Discussion started by: kavithakuttyk
1 Replies
7. Shell Programming and Scripting
I have a script script.shwhich is scheduled to run at 11 AM everyday.
# script.sh Code:
./scb_script.sh &
unfortunately scb_script.sh is running today in infinite loop as respective files are not available.
My question, when script.sh starts running tomorrow, will the old process be... (1 Reply)
Discussion started by: JSKOBS
1 Replies
8. Shell Programming and Scripting
Hi all...
I am using a for loop for another part of AudioScope...
Consider this code:-
for n in {0..100}
do
if }" = "another_string" ]
then
break
fi
done
This works perfectly except I am not sure if breaking out of a 'for' loop might cause... (2 Replies)
Discussion started by: wisecracker
2 Replies
9. Programming
Dear community,
please help with a query on Oracle. I'm using SQLPlus (but with SQLDeveloper is the same) to accamplish a sinple query like:
select count(*) from ARCHIT_D_TB where (TYP_ID=22 OR TYP_ID=23) and SUB_TM like '%SEP%' and CONS=1234This is a very simple query that works perfect until... (5 Replies)
Discussion started by: Lord Spectre
5 Replies
10. UNIX for Beginners Questions & Answers
Hi, its getting aborted with below IF loop, can plz guide me what im missing here
if || ; then
echo "print $APPEND"
fi (3 Replies)
Discussion started by: JSKOBS
3 Replies
INIT(8) System Manager's Manual INIT(8)
NAME
init, rc - process control initialization
SYNOPSIS
/etc/init
/etc/rc
DESCRIPTION
Init is invoked as the last step of the boot procedure (see boot(8)). Generally its role is to create a process for each typewriter on
which a user may log in.
When init first is executed the console typewriter /dev/console. is opened for reading and writing and the shell is invoked immediately.
This feature is used to bring up a single-user system. If the shell terminates, init comes up multi-user and the process described below
is started.
When init comes up multiuser, it invokes a shell, with input taken from the file /etc/rc. This command file performs housekeeping like
removing temporary files, mounting file systems, and starting daemons.
Then init reads the file /etc/ttys and forks several times to create a process for each typewriter specified in the file. Each of these
processes opens the appropriate typewriter for reading and writing. These channels thus receive file descriptors 0, 1 and 2, the standard
input, output and error files. Opening the typewriter will usually involve a delay, since the open is not completed until someone is
dialed up and carrier established on the channel. Then /etc/getty is called with argument as specified by the last character of the ttys
file line. Getty reads the user's name and invokes login(1) to log in the user and execute the shell.
Ultimately the shell will terminate because of an end-of-file either typed explicitly or generated as a result of hanging up. The main
path of init, which has been waiting for such an event, wakes up and removes the appropriate entry from the file utmp, which records cur-
rent users, and makes an entry in /usr/adm/wtmp, which maintains a history of logins and logouts. Then the appropriate typewriter is
reopened and getty is reinvoked.
Init catches the hangup signal SIGHUP and interprets it to mean that the system should be brought from multi user to single user. Use
`kill -1 1' to send the hangup signal.
FILES
/dev/tty?, /etc/utmp, /usr/adm/wtmp, /etc/ttys, /etc/rc
SEE ALSO
login(1), kill(1), sh(1), ttys(5), getty(8)
INIT(8)