Typeset can be used to set variable attributes, such as case, width, and left-right alignment. When typeset is used to change the attributes of a variable, this change is permanent, the following uses KSh as an example to demonstrate the typical usage of typeset. 1. If typeset is executed without any option, all variables are displayed. /Home/Lee # typeset Typeset colors Typeset-x colorterm Typeset-X Display Typeset-x gdmsession Typeset-x gnome_desktop_session_id Typeset-x gtk_rc_files Typeset-x g_broken_filenames Typeset-x histsize Typeset-x home Typeset-x hostname Typeset IFS Typeset-x inputrc Typeset-r ksh_version Typeset-x Lang Typeset-x Language Typeset-x lessopen Typeset-x LOGNAME Typeset-x ls_colors Typeset-x mail Typeset-I mailcheck Typeset-I optind Typeset-x path Typeset-I ppid Typeset-x PS1 Typeset PS2 Typeset PS3 Typeset PS4 Typeset-x pwd Typeset-I random Typeset-I seconds Typeset-x session_manager Typeset-x Shell Typeset-x shlvl Typeset-x ssh_agent_pid Typeset-x ssh_askpass Typeset-x ssh_auth_sock Typeset supported Typeset-x term Typeset-I tmout Typeset-x user Typeset-x Username Typeset-x windowid Typeset-x Xauthority Typeset-x xmodifiers Typeset _ 2: The-u option of typeset can change the character of a variable to uppercase. /Home/Lee # typeset-u Var = ABC /Home/Lee # echo $ VaR ABC 3: The-L option of typeset converts the characters of a variable to lowercase letters. /Home/Lee # typeset-L var = ABC /Home/Lee # echo $ VaR ABC 4: The-L option of typeset converts the variable to a left-aligned four strings, some of which are captured as strings :-) /Home/Lee # typeset-L4 Var = abcdefg /Home/Lee # echo $ VaR ABCD 5: The-r option of typeset converts the variable to a four-character string with the right alignment. /Home/Lee # typeset-R4 Var = abcdefg /Home/Lee # echo $ VaR Defg 6: The-Z option of typeset converts the string into an empty string that occupies 15 characters. The colon is used to protect white spaces. /Home/Lee # typeset-z15 Var = "abc ddd" /Home/Lee # echo "$ Var" ^ Abc ddd # ^ Blank /Home/Lee # typeset-lz15 Var = "abc 123" /Home/Lee # echo "$ var $ Var" Abc 123 abc 123 7: Variable N is a variable set to an integer. The typeset command fills the integer N with 0 and contains 15 characters. /Home/Lee # typeset-I n = 24 /Home/Lee # typeset-z15 n /Home/Lee # echo $ n 000000000000024 8: The answer variable is given a value -- yes and becomes a lowercase, left-aligned, one character string. /Home/Lee # typeset-ll1 answer = Yes /Home/Lee # echo $ answer Y Other typeset usage: Typeset-I num # force num to be an integer, for example: /Home/Lee # typeset-I num = 10 /Home/Lee # echo $ num 10 /Home/Lee # typeset-I16 num = 10 /Home/Lee # echo $ num 16 # /Home/Lee # typeset-I2 num = 10 /Home/Lee # echo $ num 2 #1010 /Home/Lee # typeset-i8 num = 10 /Home/Lee # echo $ num 8 #12 Typeset-X # display exported Variables Typeset a B c # If defined in a function, create a B c as a local variable Typeset-r x = var # Set a read-only variable |