I am stuck on below issue.
in my .profile. I have two variable:
when running env command, I got below:
my OS is SunOS 5.10 sun4v sparc SUNW,SPARC-Enterprise-T5220
x gets the assignment value of the string abc and the dereference of the variable $123, which if it is not set it would be undefined.
t gets the assignment value of the string xyz$. The `$' is not being interpreted by the shell as the dereference of a variable, since it exist as the last character. It is the equivalent of 'xyz$' or xyz\$
ken6503,
You haven't said which shell you're using.
I have forgotten how /bin/sh will expand $123 but I thought that:
would assign x the string abc followed by the contents of the 1st positional parameter followed by the string 23. I don't know why you didn't get the 23? If you were trying to set x to the literal string abc$123, you could do that with any of the following:
or millions of variations of any of those three possibilities.
There is nothing special about a dollar sign at the end of a string (unless the string ends with $$, so the code:
should produce the output:
I can't imagine that any shell, when given the commands:
will produce the period you showed us at the end of the output you reported:
Aia,
No, $123 does not expand to the value of the 123rd positional parameter; it expands to the value of the 1st positional parameter followed by the string 23. To get the 123rd positional parameter with a POSIX conforming shell, you would need to use ${123}. With a pure Bourne shell you can't reference any positional parameters after the 9th positional parameter directly without shifting away lower positional parameters.
And, expanding an undefined variable (including positional parameters) produces an empty string; not some undefined value.
These 2 Users Gave Thanks to Don Cragun For This Post:
Aia,
No, $123 does not expand to the value of the 123rd positional parameter; it expands to the value of the 1st positional parameter followed by the string 23. To get the 123rd positional parameter with a POSIX conforming shell, you would need to use ${123}. With a pure Bourne shell you can't reference any positional parameters after the 9th positional parameter directly without shifting away lower positional parameters.
And, expanding an undefined variable (including positional parameters) produces an empty string; not some undefined value.
Don,
Thank you for correcting that, somehow I forgot that normal variable names start with letters or underscore, thus my premises were wrong, since I was considering abc$123 as the shell trying to interpret abc$var
Quote:
which if it is not set it would be undefined
Just bad wording. I meant the variable does not exist. It is undeclared. The variable itself, not the value it can produce.
Last edited by Aia; 06-23-2015 at 09:29 PM..
Reason: Grammar
ken6503,
You haven't said which shell you're using.
I have forgotten how /bin/sh will expand $123 but I thought that:
would assign x the string abc followed by the contents of the 1st positional parameter followed by the string 23. I don't know why you didn't get the 23? If you were trying to set x to the literal string abc$123, you could do that with any of the following:
or millions of variations of any of those three possibilities.
There is nothing special about a dollar sign at the end of a string (unless the string ends with $$, so the code:
should produce the output:
I can't imagine that any shell, when given the commands:
will produce the period you showed us at the end of the output you reported:
Aia,
No, $123 does not expand to the value of the 123rd positional parameter; it expands to the value of the 1st positional parameter followed by the string 23. To get the 123rd positional parameter with a POSIX conforming shell, you would need to use ${123}. With a pure Bourne shell you can't reference any positional parameters after the 9th positional parameter directly without shifting away lower positional parameters.
And, expanding an undefined variable (including positional parameters) produces an empty string; not some undefined value.
And the thumbnail shows exactly what I said you should get for the things you showed us.
You said you got: par2=123xyz.
I said the period shouldn't be there. The period is not there in the screenshot.
You didn't show us in that screenshot what happens with the following commands:
You said you got: abc
I said that instead, it should have produced: abcsome(possibly empty)string23
where some(possibly empty)string should be the same thing you get from: printf '%s\n' "$1"
And the thumbnail shows exactly what I said you should get for the things you showed us.
You said you got: par2=123xyz.
I said the period shouldn't be there. The period is not there in the screenshot.
You didn't show us in that screenshot what happens with the following commands:
You said you got: abc
I said that instead, it should have produced: abcsome(possibly empty)string23
where some(possibly empty)string should be the same thing you get from: printf '%s\n' "$1"
Thanks Don for your reply.
Sorry, I misunderstood you. the period is type.
when I try
I got
HTML Code:
abc23
when trying
I got
could you please give me a brief explanation about this? thanks.
Hi Folks,
I have the below command that will kill all the process of an environment,
lets say if I have reached to the location cont directory under which I want to kill multiple process so the command will be ....
kill -9 `ps -ef | grep cont | grep -v grep | awk '{print $2}'`
Now please... (4 Replies)
Hello,
First post for Newbie as I am stumped. I need to get certain elements for a specific PID from the ps command. I am attempting to pass the value for the PID I want to retrieve the information for as a variable. When the following is run without using a variable, setting a specific PID,... (3 Replies)
Hello,
I have a csh script that creates an environment variable. I want to pass the environment variable(CURR_TABLE_DATE) to an Informix sql script. Here is the csh:
#!/bin/csh -f
setenv INFORMIXSERVER market3_tcp
setenv CURR_TABLE_DATE 20090714
set DATABASE = gm_cdr
set SQL_DIR =... (0 Replies)
I need to save my enviroment variables,specially the $PATH.When I put it on .cshrc at next reboot I lost the configuration.How can avoid this?Thanks (2 Replies)
What are the environment setting during a cron session?
I have HP-UX and I want to send the output/file from a script to several e-mail addresses. I want to create an env-var to store the e-mail addresses in my .profile, but I do not know if it will be visible when a script is executed in a cron. (4 Replies)
Im looking for any sample scripts that would output a current environment setup to a file and possibly then take 2 files and list any differences
This will allow us to quickly see any differences between environments in case of issue?
At a high level this would take Unix Kernel Params,... (2 Replies)
Hello...
I was wondering can anyone explain me how to set up enviroment variable to be permanent...
I tryed with setenv but my solaris does not have this command...
then I did:
export ORACLE_SID=base1
export ORACLE_BASE=/home
export ORACLE_HOME=$ORACLE_BASE/oracle/8.1.6
and by... (5 Replies)
Hi guys,
thanks in advance for this easy answer.... :s
Ok I am trying to output the enviroment varable for host in Solaris. I have tried $HOST, $HOST_NAME, $HOSTNAME carn't find it anywhere, does someone want to put me out of my misary and tell me what it is??? :confused: :eek:
Thanks... (2 Replies)
Hi.
Is it possible to remotely access another unix box via an enviroment variable, on another machine?
I am trying to create an environment variable $MIPSDATA which will point to a folder on another machine.
I have setup the .rhosts file and got that working on both machines (tested via a... (4 Replies)
:confused: Hi, does anyone here know how to compile and run C++ in UNIX environment? I am so desperate! Any help is greatly appreciated. Thanks! (3 Replies)