Bash advanced variables

bash arrays

There are cases when you want to avoid this kind of behavior, for instance when handling telephone and other numbers. Apart from integers and variables, you may also want to specify a variable that is a constant. This is often done at the beginning of a script, when the value of the constant is declared. … Continue reading Bash advanced variables

Bash select menu and shift

bash select menu

The select construct allows easy menu generation. The syntax is quite similar to that of the for loop: select WORD [in LIST]; do RESPECTIVE-COMMANDS; done LIST is expanded, generating a list of items. The expansion is printed to standard error; each item is preceded by a number. If in LIST is not present, the positional … Continue reading Bash select menu and shift

Bash repetitive tasks ( for , while , until )

Bash repetitive tasks ( for , while , until )

To run a specific task or list of commands repetitively on bash script , you need to use on of this three constructions : for , while , until . Each one fits different situation as we will know now. The for loop The for loop is the first of the three shell looping constructs. … Continue reading Bash repetitive tasks ( for , while , until )

Bash interactive scripts

bash interactive scripts

Some scripts run without any interaction from the user at all. Advantages of non-interactive scripts include: The script runs in a predictable way every time. The script can run in the background. Many scripts, however, require input from the user, or give output to the user as the script is running. The advantages of interactive … Continue reading Bash interactive scripts

Bash conditional if and case statements

At times you need to specify different courses of action to be taken in a shell script, depending on the success or failure of a command. The if construction allows you to specify such conditions. The most compact syntax of the if command is: if TEST-COMMANDS; then CONSEQUENT-COMMANDS; fi The TEST-COMMAND list is executed, and … Continue reading Bash conditional if and case statements

How to use awk

AWK is another popular stream editor, just similar to SED. The basic function of awk is to search files for lines or other text units containing one or more patterns. When a line matches one of the patterns, special actions are performed on that line. There are several ways to run awk. If the program … Continue reading How to use awk