Definition of $-


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Definition of $-
# 8  
Old 06-09-2009
The following applies to vanila ksh93t. The set of possible characters retuned by $- is:
Code:
DircabefhkmnpstuvxBCGEl

The meaning of these can be mostly inferred from the following defines which match the order of the above characters
Code:
SH_DICTIONARY, SH_INTERACTIVE, SH_RESTRICTED, SH_CFLAG,
SH_ALLEXPORT, SH_NOTIFY, SH_ERREXIT, SH_NOGLOB, SH_TRACKALL,
SH_KEYWORD, SH_MONITOR, SH_NOEXEC, SH_PRIVILEGED, SH_SFLAG, SH_TFLAG,
SH_NOUNSET, SH_VERBOSE,  SH_XTRACE, SH_BRACEEXPAND, SH_NOCLOBBER,
SH_GLOBSTARS, SH_RC, SH_LOGIN_SHELL

where SH_CFLAG, i.e. 'c', is set if ksh93 is involved with a "-c cmdstring" command line option.
# 9  
Old 06-09-2009
Code:
/home/jmcnama> echo $-
isam
/home/jmcnama> ksh -c
echo $-
shc
exit
/home/jmcnama> echo $-
isam
/home/jmcnama> set -v
/home/jmcnama> echo $-
echo $-
ivsam
/home/jmcnama>

$- with a "c" in it means the shell was invoked with -c. Period. It does not tell you more than that. As you can see $- shows both invocation options, plus any options you set later on, in this example verbose was turned on interactively.

$- reflects BOTH options set at shell invocation and set later on. It is there to let you know what your runtime environment is like, -v for example, changes the way the running script appears to the user.
# 10  
Old 06-11-2009
Ok, I guess I was wrong. That was exactly what I was looking for. The last two posts have given enough detail to explain to me what I was unable to find in any of the man pages.

So now I would like to know how you found this information. I have looked at both the ksh and bash man pages in detail and cannot find anything that explains the association of the individual letters with these options (at least for many of them). In fact, in the man pages I'm looking at on Solaris 10, there are no options that even begin with "SH_". And many of the options are ambiguous if you simply look at the first letter (i.e. hashall, histexpand, history; or emacs, errtrace; or physical, pipefail, posix, privileged; etc.)

Anyway, thanks for the info.
# 11  
Old 06-11-2009
For ksh: the man page for ksh explains them. Look for the set keyword. ksh88 is what I showed you - this is what Solaris supports by default. fpMurphy showed you ksh93 - which is an add-on that you used to have to purchase separately.
There is also pdksh[number] a public domain version with newer features.
Code:
echo $SHELL

will tell you which one you are running.

The point is - there are some very different new features in ksh93, many of which are involved in PITA part of shell programming - string splitting, date arithmetic, etc. So your results may vary depending on your shell version.

Last edited by jim mcnamara; 06-11-2009 at 11:52 AM..
# 12  
Old 06-11-2009
The '$-' (and its friends $$, $? etc) are described in 'man ksh' under the header 'Parameters Set by Shell' (on Solaris). Here's the snippet:
Code:
  Parameters Set by Shell
     The following parameters are automatically set by the shell:

     #     The number of positional parameters in decimal.

     -     Flags supplied to the shell on invocation  or  by  the
           set command.

     ?     The decimal value returned by the last  executed  com-
           mand.

For the 'set -v' (and its friends), 'man ksh' and search for the 'Special Commands' header (on Solaris again). Here's the snippet of that:
Code:
Special Commands
...........
...........
     set [ +abCefhkmnopstuvx ] [ +o option ]... [ +A name ]  [ arg ...
           The flags for this command have meaning as follows:

           -A    Array assignment. Unsets the variable  name  and
                 assigns  values  sequentially from the list arg.
                 If +A is used, the variable name  is  not  unset
                 first.

           -a    All subsequent variables that  are  defined  are
                 automatically exported.

# 13  
Old 06-11-2009
Quote:
Originally Posted by sszd
So now I would like to know how you found this information. I have looked at both the ksh and bash man pages in detail and cannot find anything that explains the association of the individual letters with these options (at least for many of them). In fact, in the man pages I'm looking at on Solaris 10, there are no options that even begin with "SH_". And many of the options are ambiguous if you simply look at the first letter (i.e. hashall, histexpand, history; or emacs, errtrace; or physical, pipefail, posix, privileged; etc.)
The information I provided is based on my knowledge of the ksh93 source code. It is not really documented fully in the man page or elsewhere.

Note that this information only pertains to ksh93 and not to pdksh, ksh88 or bash.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Get struct definition

I have many headers with huge amount of structures in them, typical one looks like this: $ cat a.h struct Rec1 { int f1; int f2; }; struct Rec2 { char r1; char r2; }; struct Rec3 { int f1; float k1; float ... (6 Replies)
Discussion started by: migurus
6 Replies

2. UNIX for Advanced & Expert Users

Variable definition

Hi all, I'm bit new to the advanced bash shell scripting. When I'm looking at some of the existing code in my organization, got confused with a few variable definings. For ex: var1={1:-30} var2="abc def ghi" var3={xyz:-$var2} In above, 1st and last lines are confusing me.... (4 Replies)
Discussion started by: raghu.iv85
4 Replies

3. What is on Your Mind?

Definition of Bytes

A byte is the smallest unit of storage which can be accessed in a computer's memory- either in RAM or ROM.It also holds exactly 8 bits.But its old view one byte was sufficient to hold one 8 bit character.Modern days especially on .NET or international versions of Win 32, 16 bits is needed. ... (2 Replies)
Discussion started by: stoudtLion
2 Replies

4. Fedora

Shell parameter definition

Hi Folks, I have a script called program.sh which was written by someone. I am supposed to edit it for my necessities. There is a line in the script that is as follows if ]; then echo -e "Option limit should be positive number and less than 1. Program aborts!" exit 1 ... (27 Replies)
Discussion started by: jacobs.smith
27 Replies

5. HP-UX

macro definition in FTP

Hi, I am trying to create a macro in FTP to rename multiple files.Below given is the codewhich i tried. I wanted to pass the files from the file "$FTPTXRENAMESUCLIST`" to the renfiles macro. Your help will be really appreciated. ftp -i -v -n << endftp > $FTPTXLOG 2> $FTPER open... (0 Replies)
Discussion started by: tinivt
0 Replies

6. UNIX for Dummies Questions & Answers

What is inside the definition of Unix?

Is FreeBSD and OpenBSD considered Unix? What O.S does Most of the forum members use? How popular are Licensed Unix operating systems for home users? Additionally I thought Linux was a Minux fork and BSD was a Unix fork. Thanks in ... (7 Replies)
Discussion started by: theKbStockpiler
7 Replies

7. Shell Programming and Scripting

daemons definition

hi there, can somebody give me a definition for daemons, or example what are they !! and what the use for? i've done some research and all what i found is /etc/... or /usr/bin/... and i haven't quietly got the concept. any ideas !! Thanks. (5 Replies)
Discussion started by: new2Linux
5 Replies

8. UNIX for Dummies Questions & Answers

Paging space definition

sorry for this silly question, I am new to UNIX, what is meant by paging space and what is its purpose? what is also meant by hd6 paging space? (2 Replies)
Discussion started by: docaia
2 Replies

9. Programming

process image + definition

Ive seen this word being popped up whenever I read the Unix man description of the exec() family of functions. What exactly does it refer to, as I can't seem to comprehend how processes would have an image ? cheers (1 Reply)
Discussion started by: JamesGoh
1 Replies

10. UNIX for Dummies Questions & Answers

Printer definition file on HP

Hello, I'm looking for the definition file for printers on HP. Can I implement printers.conf like on SUN ? Thanks for your help:( (4 Replies)
Discussion started by: annececile
4 Replies
Login or Register to Ask a Question