I used bash shell and it works exactly fine.the variable $1 is unset.Let me know which shell you use and I can try on it , if I have access to the same.
Well, you can thank the forum administrator for all the confusion. I originally posted this question in the AIX FORUM since this behavior seemed to be specific to AIX.
First off, I'd like to state for the record, that you should thank yourself instead of thanking me: you haven't made clear that this occurs only in AIX (to your knowledge) and among the many things i am incompetent in is reading minds. Furthermore it will become clear with the answer that i was correct moving the thread as it is indeed a shell-related problem, not a OS-related one. In fact it is a problem of understanding, not of software.
Further, and to clear up the confusion: This effect can probably be demonstrated in other implementations of the Korn Shell too, as it is no bug, but a feature. You execute a script IN THE CURRENT ENVIRONMENT and hence you can set any variable and it will stick to this value until being changed. The same is the case with system variables like $1, which you are setting here - in your current environment. You can query the value of $1 also in the current environment:
It may look a bit counter-intuitive, but: which reason would the shell have to change the value of "$1" as long as it isn't being changed?
After this explanation the solution how to clear the variable "$1":
Either provide an empty value to make it empty:
or use "shift" to rotate out $1:
One word about the implementation of bash: *this* in fact is a bug and the failure of the Linux pdksh to do the same as the AIX ksh should be regarded as sloppiness of implementation, not as feature.
Sorry but I disagree. Where is the variable "1" being set? The line "echo 1=$1" does not define or assign any variable. It tells the shell to expand $1 (in this case, XXX) and output "1=XXX"
You are right and wrong, fpmurphy: The variable 1 is not set in the echo-statement. It is merely displayed there. It is set when the script is started and as the script is started in the current environment the variable is set in the current environment.
When you execute "script 1", you start a new shell environment, then set the variable 1 in this environment to "1" and then the script starts to run, yes? If you issue ". script 1" you do not start a new environment but the rest of the procedure occurs quite the same.
Good, Bakunin, we agree that the variable "1" is not set by the "echo 1=$1" statement.
You claim that $1 (first positional paramater) should be available in your current environment upon sourcing a file such as in the example provided
Sorry, again, I must disagree. Positional parameters are initially assigned when you invoke a shell, temporarily replaced when a shell function is invoked, and can only be reassigned with the set special built-in command.
$1 is available within the testme script but not outside it. To illustrate this point, try the
following:
which gives the following output
Have you a counter example to disprove my assertion?
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)