Home » Infrastructure » Linux » Help needed with Shell script !!
icon8.gif  Help needed with Shell script !! [message #116580] Wed, 20 April 2005 13:28 Go to next message
vishamr2000
Messages: 18
Registered: April 2005
Junior Member
Hi to all,

I badly need some help with this. I need a shell script version of some C code I wrote. The basic idea is as follows:

variable x is given the value of 1 at start in script. When it goes down the function, I want it to retain the value at which the program terminated when it first ran so that when the program runs a second time, it takes the last value that x got assigned (that is either a 0 or a 1).

if(x==1)
{

printf("Good Morning!!");
x=0;
}

else
if(x==0)
{

printf("Good Afternoon!!");
x=1;
}

Thx in advance..
Regards,
Visham
Re: Help needed with Shell script !! [message #116862 is a reply to message #116580] Fri, 22 April 2005 10:07 Go to previous messageGo to next message
Frank Naude
Messages: 4571
Registered: April 1998
Senior Member
Try something like this:

#!/bin/ksh

if [ ! -r x ]; then
  # No value from previous run - initialize x
  x=1
else
  x=$((`cat x`))
  echo "Value of x from previous run = $x"
fi

if [ x -eq 1 ]; then
  echo "Good Morning!!"
  x=0;
else
  echo "Good Afternoon!!"
  x=1;
fi

# Save variable to file
echo $x >x


Best regards.

Frank
icon10.gif  Re: Help needed with Shell script !! [message #116879 is a reply to message #116580] Fri, 22 April 2005 12:24 Go to previous message
vishamr2000
Messages: 18
Registered: April 2005
Junior Member
Many thx for the reply Frank..

I'll give it a try and then let you know how it goes.

Thx again..

Regards,
Visham
Previous Topic: emctl says database is down
Next Topic: oracle10g - netmgr works but no tnsping
Goto Forum:
  


Current Time: Mon Feb 06 06:37:23 CST 2023