bakunin - I appologize. I did not "state" that the problem was in AIX, I merely tried to imply it by placing the question in the AIX Forum - and it seems that that still mis-characterizes it since it's really a ksh issue.
I did find an answer to my question - which was
Quote:
The question is - how do I clear that $1 value???
An answer is to use the following:
or, as was pointed out earlier by bakunin, use the shift command to shift the positional parameters until they are all empty. For what I am looking for, set -- is more efficient.
Ok - let's lay this out this issue/question a bit better. My issue is that when I am dot-running a script over and over, I don't want the positional parameters to persist in my session. If they do, then I can never re-dot-run the script - or any other script - with NO parameters. In addition, my actual script is scrutinizing the $1 parameter and checking for specific values - so just passing in a "" as the first parameter actual fails my check and spit out a USAGE message explaining how to use the script. The first positional parameter is used to activate optional functions within the script. To just run the script "normally" without the optional features, you don't pass in a parameter.
And there in lies my problem.
The solution for me was to set a Variable=$1 (and repeating that for all other passed in parameters as needed) and immediately issuing set --. This clears all positional parameters that were permanently set for my current environment/session (due to the use of dot-run).
Problem solved.
Now - to address some of the other comments/assertions being made in the other comments/replies posted here:
Here's some new code for testme which shows an example of how I am checking the value of $1 in my "real script" (which I have still not shown you - but we are trying to keep things simple here).
Now run these commands and observe the output.
First, let's clear all positional parameters:
set --
Now let's start our experiment:
. testme There were no parameters passed into this script
. testme DB There was at least 1 Parameter passed into this script and $1 was "DB"
. testme There was at least 1 Parameter passed into this script and $1 was "DB"
The above output shows that $1 persists in the current environment. This is NOT the behavior I need/want.
. testme "" There was at least 1 Parameter passed into this script and $1 was not "DB"
The above output shows that $1 is not empty and thus fails the test
if [[ ! "${1}" = "DB" ]]
This is NOT the behavior I need.
This also shows that $1 is available in your current environment/session. To further prove this, run the following commands:
. testme DB There was at least 1 Parameter passed into this script and $1 was "DB"
echo 1=$1 1=DB
The value in $1 would persist and potentially mess with other scripts ONLY when those scripts are dot-run. I hope you would agree that this is NOT a desirable behavior. set -- takes care of that behavior by wiping clean all positional parameters ($1, $2, $3, etc)
First off, I'd like to apologize to fpmurphy and HobieCoop if they had the impression of a fight going on - this is not the case. In fact i'm enjoying tremendously the possibility to gnaw my teeth into a problem which is *not* all-too-obvious to solve.
fpmurphy has raised some interesting points, but i need a bit of time to come up with a (clever) response.
HobieCoop, Bakunin and I are not fighting. We are simply trying to come up with a correct understanding of the interesting problem presented to us by you.
The AIX ksh behaviour discussed in this thread might be different depending on which ksh version is used to call the dot command. IIRC AIX came with both ksh88 and ksh93 since V5.2. While the ksh93 implementation in AIX was quite buggy (e.g. using it as default login shell could lead to the user being unable to log in) it seems to be usable in the current oslevels.
I assume that most posters used AIX ksh88 (which is still the AIX default shell) for testing. I am unsure about the environment fpmurphy used as
Quote:
Originally Posted by fpmurphy
[...]
does not look like an AIX ksh93 to me straight away.
However, I am going to point out some difference between the two ksh versions coming with AIX 5L. Ksh versions are identical in the current versions of 5.2 and 5.3. My samples were collected from an AIX 5.3 server.
I copied HobieCoop's script from his previous post. I first run the script in ksh88. Mind that the script itself calls /bin/ksh in both tests I am going to do.
First the script runs in ksh88 which has not changed in the last years and probably won't in the future.
So this is the test outcome HobieCoop complained about.
Second test, but this time in ksh93 as starting shell
The difference could be considered either a bug or a feature. Regardless using ksh93 would spare HobieCoop from having to flush the whole environment to clear the $1 value.
Hi,
I have created a script to clear up the /var filesystem once it reaches > 90%.
This is part of the script :
#!/bin/bash
DIR = ./adm
DIR2=./adm/sw
DIR3 = ./spool/mqueue
DIR4 = ./adm/syslog
DIR5 = ./adm/sulog
DIR6 = ./tmp
F1 = ./tmp/dead.letter
F2 = ./adm/wtmps
file1 =... (5 Replies)
Hi,
I have a script which does couple of database connection and run some SELECT queries to get some output in the file.
I am surprised to see :eek: that when i run my script some times it gives the desired out put and sometimes it shows some error :confused: .
Suppose if i execute it say... (3 Replies)
I am using blow script :--
#!/bin/bash
FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not
if
then
# echo "process found"
exit 0;
else
echo "process not found"
exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
I am new to Shell Scripting and need some help.
The following batch job has been failing for me due to the .nfsxxx files in use. I need to know how to modify the following script to exclude the .nfsxxx files so this batch job will not fail on me. I have done lots of googling and keep coming back... (2 Replies)
Good day UNIX forum, could you help me with my clear printer queue script, i have problems with the consistency of this function, sometimes it works sometimes it doesn't. Thanks in advance
}
preRemovePrintQ(){
clear;
echo;
echo... (1 Reply)
OS SCO Open Server 6.0 MP4
I am trying to change the value of a enviornment variable thru a script and want to pass a parameter on the commande line, If I hard code the value inside the script the script changes the enviornment variable
. mytest
where my test is
MYVAR=$1
export MYVAR... (6 Replies)
Hi,
i have a script which need to do behave differently when run as a startup process from init.d/ rc2.d script and when run manually from shell.
How do i distinguish whether my script is run by init process or by shell??
Will the command
/proc/$$/psinfo | grep "myscript" work well???... (2 Replies)
I have a log file on our system which fills up with lines that have been timestamped, as follows....
03/03/2008 10:56:06:815] (ERROR) balance: continuing session to genapp02 : 18500
03/03/2008 10:56:06:820] (ERROR) balance: continuing session to genapp02 : 18500
03/03/2008 10:56:07:003]... (2 Replies)
Hello. I should have asked this awhile ago but here is my situation. My task is to generate LOC for different directories. I have a text file that has dates in this format (01-Aug-2006). My task is to read each line and compare it to a branch date. Depending on the date, it should generate a... (0 Replies)