Question

I'm in the process of porting over a script from HP-UX to LINUX. When I try to source the script, bash complains that

bash: typeset: -u: invalid option
typeset: usage: typeset [-afFirtx] [-p] name[=value] ...

typeset: usage: typeset [-afFirtx] [-p] name[=value] ...
./install_profile: line 237: typeset: -l: invalid option

From what I can see, typeset is used to assign a value to a variable, although I don't quite understand what typeset -u and typeset -l do specifically that's different from a general assignment such as foo="bar".

I was wondering if there was some equivalent way to express typeset -u and typeset -l for LINUX bash since it does not appear to be compatible with bash.

Altneratively, I was wondering if it would be possible to get the typeset commands recognized as ksh commands, since it appears that typeset is from ksh.

Thanks.

Was it helpful?

Solution

What versions of bash are you porting from/to? typeset -l makes the variable such that any assignment to it converts upper case to lower case; typeset -u converts lower to upper. I suspect those options were added to bash sometime around version 4.

OTHER TIPS

The behavior of typeset -l and -u are basically the same in Bash, ksh93, and mksh, where it they cause strings to be converted to lower or uppercase respectively on assignment. In ksh, they additionally act as modifiers for long ints and floats, which aren't common shell features (Bash doesn't have these). Using -u and -l are generally discouraged especially in large scripts where they can let bugs slip in. There are better alternatives most of the time using the case-modification parameter expansions.

typeset under Bash is a synonym for declare (Bash considers typeset deprecated - IMO this isn't a major issue). There are many significant differences between them and they should generally be considered incompatible unless you take care to know their exact behavior. In both shells, they play a major role in defining datatypes (Bash, zsh, and mksh all have some non-overlapping support that's much more limited than ksh93).

Also, there's no problem with installing ksh93 (or the whole AST toolkit) under Linux and probably no need to port your script to Bash unless you really want to. Bash is far more popular as a default under Linux mainly for historical reasons, and to a certain extent, licensing (copyleft).

$ echo $VAR_NAME | tr '[:upper:]' '[:lower:]'
$ echo $VAR_NAME | tr '[:lower:]' '[:upper:]'

Source: http://www.cyberciti.biz/faq/linux-unix-shell-programming-converting-lowercase-uppercase/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top