Solaris / OpenSolarisThis forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Note that most UNIX/Linux commands have manual pages (called man pages). For any command you see you should be able to type "man <command>" to get more detail of what the command does and what arguments and flags it allows for. (There are man pages for things that aren't commands but are helpful - e.g. configuration files and concept pages or lists for example "ascii" will give you the ascii table with its mappings to decimal, and other notations.)
What you're looking at is a "shell script". A lot of what you need to know (loops, if/then, case etc...) is described in the man page for the specific shell. e.g. "man ksh" would give you details of the Korn Shell, "man bash" would give you details of the Bourne Again Shell.
You really need to look at man pages to get more details on a lot of this.
Having said that I'll go over some of what you're seeing here:
First line is setting a variable named "FINISHED" to have the value "Done".
Later references to the variable would use that value. e.g. if the script contained "echo $FINISHED" you'd see it output the word "done". (Variable declaration is described in the shell man pages.)
Next line is setting a variable named "COLUMNS". It is using a pipeline command output to set the variable. Enclosing the pipeline in $() tells it to first execute the pipeline and then use its result.
A pipe (the vertical bar) tells it to send output of one command as input to the next command. A command line that has pipes on it is commonly called a pipeline. (Described in shell man pages.)
"stty" is a command for dealing with terminal/serial line characteristics. The "-a" flag tells it to output all the characteristics currently set for the terminal on which this command is being run. (man stty for more details)
"head" is a command for displaying lines from the start of output. (A similar command is "tail" which displays lines from end of output.) The "-n 2" flag says to limit the output to the first 2 lines. (man head for more details)
The "stty -a" output is being piped into "head -n 2" so that part of the pipeline is limiting the "stty -a" output to first 2 lines.
The "cut" command is a command to parse data on each line - specifically to extract out only a certain portion of the line. (The "awk" command has far more functionality by the way but "cut is good for quick and dirty.) The "-d" tells cut what to use for delimiter (text separator) from the input. Since that is follow by a space with double quotes around it the command says to use a space for delimiter. The "-f" tells it which delimited field(s) to output. Since it has "-f4" it is saying to output the 4th field. (man cut for more details)
Since the output of the "head -n 2" is being piped into the "cut" command you are now seeing only the 4th field of the first 2 lines of the "stty -a" output. The COLUMNS variable now contains that information.
By now you should see that the next thing is setting a variable called RET_ARR to value \010. (Such notation suggests an ascii value is being set for special coding because of the "\" in the variable name.
They're next setting a new variable to have the prior variable twice. (e.g. \010\010) However since this is ascii notation there may be something else going on there.
Next there is "loop" being done. This is a "for" loop. For loops execute for each item in the list they are given. (Described in shell man pages.)
At this point I think you should have the idea. You need to review each of the commands in light of the appropriate man pages to understand what they are doing.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.