Sponsored Content
Top Forums Shell Programming and Scripting Typeset conversion problem from ksh to bash Post 302401260 by kanagaraj on Friday 5th of March 2010 10:01:17 AM
Old 03-05-2010
Hi,

In bash we can use decare instead of typeset but its options is limited.
Code:
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]

I used functions , its worked fine
Code:
toUpper() { echo $1 | tr "[:lower:]" "[:upper:]" } GENDER=male GENDER=`toUpper $GENDER` echo $GENDER
toLower() { echo $1 | tr "[:upper:]" "[:lower:]" } GENDER=MALE GENDER=`toLower $GENDER` echo $GENDER

Thnks,
kanagaraj

Last edited by radoulov; 03-05-2010 at 11:04 AM.. Reason: Code tags, please!
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with Darwin typeset -i

From the bash manpage: typeset ] What I'm trying to do is add two values in hexadecimal and have the resulting number display in hexadecimal. What I get is the result displayed in decimal. For instance: a=0x10 b=0x30 ((c=a+b)) echo $c ...displays 64. The arithmatic is correct, but the... (2 Replies)
Discussion started by: Loriel
2 Replies

2. UNIX for Dummies Questions & Answers

typeset in Ksh

Hi, Most of times, I see use of typeset command in ksh scripts, but I don't know what it exactly does. I would be thankful if any body could provide me a brief explanation of typeset in ksh and all of its options, like typeset -A, typeset -r, typeset -Z, typetset -L etc. (5 Replies)
Discussion started by: nervous
5 Replies

3. Shell Programming and Scripting

Conversion question about ksh

Hi all, New to ksh and had a few questions to see if this is doable in ksh or if I am going to have to call out to a tcl procedure. I have an Ascii file I want to convert to hex then search and remove all hex chars '0A' and then convert back to Ascii. Here is an example of an Ascii file I am... (2 Replies)
Discussion started by: hgjdv
2 Replies

4. Shell Programming and Scripting

Help with typeset in bash

Hi everybody, hoping you can help. I'm trying to get some scripts working using bash which were written in ksh and I'm struggling with typeset. Specifically typeset -R and typeset -L. We need fixed length variables with left and right justification and bash does not seem to do it. Spent ages on... (5 Replies)
Discussion started by: Ian_H
5 Replies

5. Shell Programming and Scripting

bash typeset padding with zeros

Hi everybody, I have a question about typesetting. I originally wrote a script for use with ksh and now I am on a system that I cannot modify, and it only has bash. In the original script I just did typeset -RZ4 variable and it would add the leading zeros. In bash, it doesn't work. I've... (2 Replies)
Discussion started by: jwheeler
2 Replies

6. Shell Programming and Scripting

bash & Ksh loop problem

hi i was trying to optimize one script and i came across this problem .. i am putting some pseudo code here $ >cat a.sh ls | while read I do i=$(($i + 1)) done echo "total no of files : " $ >ksh a.sh total no of files : $ >bash a.sh total no of files : why is... (1 Reply)
Discussion started by: zedex
1 Replies

7. Shell Programming and Scripting

converting ksh to bash - typeset commands

Hi all, Am trying to convert a script written in ksh to a bash shell. At the moment, am stumped with the typeset -u command and I can't find an equivalent of it in bash. integer function is also not working as is the following if statement if ] && ]; then continue fi Is... (3 Replies)
Discussion started by: newbie_01
3 Replies

8. Shell Programming and Scripting

Bash to ksh problem

Hi all Below code works in bash but it is not working in ksh. enddate=`date -d "$enddate + $i day" "+%Y_%m_%d"` Please help me how it works in ksh Thanks (10 Replies)
Discussion started by: pmreddy
10 Replies

9. Shell Programming and Scripting

ksh "typeset -i" and Empty Parameters

I'm getting different behaviors for "typeset -i" on different systems. In one case unset parameters are 0, and in another case they're empty. Is one of these behaviors correct, or is the behavior here unspecified? First system: $ typeset -i x $ print $x 0 $ print ${.sh.version} Version M... (13 Replies)
Discussion started by: Matt Miller
13 Replies
typeset(1)							   User Commands							typeset(1)

NAME
typeset, whence - shell built-in functions to set/get attributes and values for shell variables and functions SYNOPSIS
typeset [+- HLRZfilrtux [n]] [name[=value]]... whence [-pv] name... ksh93 ++typeset [+-AHflbnprtux] [+-EFLRZi[n]] [vname[=value]] whence [-afpv] name... DESCRIPTION
ksh typeset sets attributes and values for shell variables and functions. When typeset is invoked inside a function, a new instance of the variables name is created. The variables value and type are restored when the function completes. The following list of attributes can be specified: -f The names refer to function names rather than variable names. No assignments can be made and the only other valid flags are -t, -u and -x. The flag -t turns on execution tracing for this function. The flag -u causes this function to be marked undefined. The FPATH variable is searched to find the function definition when the function is referenced. The flag -x allows the function definition to remain in effect across shell procedures invoked by name. -H This flag provides UNIX to hostname file mapping on non-UNIX machines. -i Parameter is an integer. This makes arithmetic faster. If n is non-zero it defines the output arithmetic base; otherwise, the first assignment determines the output base. -l All uppercase characters are converted to lowercase. The uppercase flag, -u is turned off. -L Left justify and remove leading blanks from value. If n is non-zero it defines the width of the field; otherwise, it is determined by the width of the value of first assignment. When the variable is assigned to, it is filled on the right with blanks or truncated, if necessary, to fit into the field. Leading zeros are removed if the -Z flag is also set. The -R flag is turned off. -r The specified names are marked readonly and these names cannot be changed by subsequent assignment. -R Right justify and fill with leading blanks. If n is non-zero it defines the width of the field, otherwise it is determined by the width of the value of first assignment. The field is left filled with blanks or truncated from the end if the variable is reassigned. The -L flag is turned off. -t Tags the variables. Tags are user definable and have no special meaning to the shell. -u All lowercase characters are converted to uppercase characters. The lowercase flag, -l is turned off. -x The specified names are marked for automatic export to the environment of subsequently-executed commands. -Z Right justify and fill with leading zeros if the first non-blank character is a digit and the -L flag has not been set. If n is non- zero it defines the width of the field. Otherwise, it is determined by the width of the value of first assignment. The -i attribute can not be specified along with -R, -L, -Z, or -f. Using + rather than - causes these flags to be turned off. If no name arguments are specified but flags are specified, a list of names (and optionally the values) of the variables which have these flags set is printed. (Using + rather than - keeps the values from being printed.) If no names and flags are specified, the names and attributes of all variables are printed. For each name, whence indicates how it would be interpreted if used as a command name. The -v flag produces a more verbose report. The -p flag does a path search for name even if name is an alias, a function, or a reserved word. On this manual page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ksh93 If the -f option is not specified, typeset sets, unsets, or displays attributes of variables as specified with the options. If the first option is specified with a - then the attributes are set for each of the specified names. If the first option is specified with a +, then the specified attributes are unset. If =value is specified, value is assigned before the attributes are set. When typeset is called inside a function that is defined with the function reserved word, and name does not contain a ., a local variable statically scoped to that function is created. Not all option combinations are possible. For example, the numeric options -i, -E, and -F cannot be specified with the justification options -L, -R, and -Z. The following preset aliases are set by the shell: float typeset -E functions typeset -f integer typeset -i nameref typeset -n If no names are specified, variables that have the specified options are displayed. If the first option is specified with a leading - then the name and value of each variable is written to standard output. Otherwise, only the names are written. If no options or only the -p option are specified, the names and attributes of all variables that have attributes are written to standard output. When -f is specified, the names displayed are function names. If -f is specified, then each name refers to a function and the only valid options are -u and -t. In this case no =value can be specified. typeset is built-in to the shell as a declaration command so that field splitting and pathname expansion are not performed on the argu- ments. Tilde expansion occurs on value. The following options are supported by the typeset built-in command in ksh93: -a Indexed array. This is the default. -A Associative array. Each name is converted to an associative array. If a variable already exists, the current value becomes index 0. -b Each name can contain binary data. Its value is the mime base64 encoding of the data. This option can be used with -Z, to specify fixed sized fields. -E [n] Floating point number represented in scientific notation. n specifies the number of significant figures when the value is expanded. The default value is 10. -f Each of the options and names refers to a function. -F [n] Floating point. n is the number of places after the decimal point when the value is expanded. The default value is 10. -H Hostname mapping. Each name holds a native pathname. Assigning a UNIX format pathname causes it to be converted to a pathname suitable for the current host. This has no effect when the native system is UNIX. -i [base] An integer. base represents the arithmetic base from 2 to 64. The option value can be omitted. The default value is 10. -l Convert uppercase characters to lowercase characters. Unsets the -u option. When used with -i, -E, or -F indicates long vari- ant. -L [n] Left justify. If n is specified, it represents the field width. If the -Z attribute is also specified, then leading zeros are stripped. The option value can be omitted. -n Name reference. The value is the name of a variable that name references. name cannot contain a .. -p Causes the output to be in a format that can be used as input to the shell to recreate the attributes for variables. -r Enables read-only. Once this option is enabled, it cannot be disabled. See readonly(1). -R [n] Right justify. If n is specified it represents the field width. If the -Z option is also specified, zeros are used as the fill character. Otherwise, SPACEs are used. -s Restricts integer size to short when used with -i. -t When used with -f, enables tracing for each of the specified functions. Otherwise, -t is a user defined attribute and has no meaning to the shell. -T tname tname is the name of a type name given to each name. -u Without -f or -i, converts lowercase characters to uppercase and unsets -l. When used with -f, specifies that name is a func- tion that has not yet been loaded. When used with -i specifies that the value is displayed as an unsigned integer. -x Puts each name on the export list. See export(1). name cannot contain a .. -Z [n] Zero fill. If n is specified it represents the field width. The option value can be omitted. The following exit values are returned by typeset in ksh93: 0 Successful completion. >0 An error occurred. If the -v is not specified, whence writes on standard output an absolute pathname, if any, corresponding to name based on the complete search order that the shell uses. If name is not found, no output is produced. If the -v is specified, the output from whence also contains information that indicates how the specified name would be interpreted by the shell in the current execution environment. The following options are supported by the whence built-in command in ksh93: -a Display all uses for each name rather than the first. -f Do not check for functions. -p Do not check to see if name is a reserved word, a built-in, an alias, or a function. -v For each name specified, the shell displays a line that indicates if that name is one of the following: o Reserved word o Alias o Built-in o Undefined function o Function o Tracked alias o Program o Not found The following exit values are returned by whence in ksh93: 0 Successful completion. Each name was found by the shell. 1 One or more names were not found by the shell. >1 An error occurred. On this manual page, ksh93(1) commands that are preceded by one or two + (plus signs) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. They are not valid function names. 5. Words, following a command preceded by ++ that are in the format of a variable assignment, are expanded with the same rules as a variable assignment. This means that tilde substitution is performed after the = sign and word splitting and file name genera- tion are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), ksh93(1), readonly(1)set(1), sh(1), attributes(5) SunOS 5.11 13 Mar 2008 typeset(1)
All times are GMT -4. The time now is 06:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy