• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Shell Scripting

How to Use user-defined Functions in awk

By admin

User-Defined Functions You can create user-defined functions in a awk script file using the func or function keywords. Placement in the file is not important; the function definition can occur anywhere in the awk script. The function can take arguments (local to the function only) or use any existing variable. The syntax of a function definition is: func function_name ([optional_arg] . . .) { statements } or function function_name ([optional_arg] . . .) { statements } The … [Read more...] about How to Use user-defined Functions in awk

Filed Under: DevOps, Shell Scripting

Using Loops (while, for) in awk scripts

By admin

The awk programming language contains many of the programming concepts that are used in shell scripting. Conditionals, such as the if statement and loops, such as the following can also be used in awk programming. The while loop The do while loop The for loop The if Statement The if statement can have two branches: an if branch and an else branch. If the condition is true, the if branch is executed; if the condition is false, the else branch is executed. if (condition) { … [Read more...] about Using Loops (while, for) in awk scripts

Filed Under: DevOps, Shell Scripting

Beginners Guide to Using “trap” to Catch Signals and Handle Errors in Shell Script

By admin

Shell Signal Values A signal is a message that some abnormal event has taken place or a message requesting another process do something. The signal is sent from one process to another process. Typically, a process sends a signal to one of its own subprocesses. You can obtain more information on signals from the signal and kill man pages. You use the kill command to send signals to processes. The root user can send any signal to any process. Other users can only send signals to processes they … [Read more...] about Beginners Guide to Using “trap” to Catch Signals and Handle Errors in Shell Script

Filed Under: DevOps, Shell Scripting

How to Make a Variable read-only (constant) in Bash and Korn Shell

By admin

Creating Bourne Shell Constants A variable can be made read-only with the following syntax: readonly var[=value] The square brackets around =value mean that the assignment of a value is not always necessary. For instance, if the variable had previously been created and assigned a value, and you now want to make it read-only (and not change its current value), do not use =value. If the variable did not previously exist, and you make it read-only, you may never assign a value to the … [Read more...] about How to Make a Variable read-only (constant) in Bash and Korn Shell

Filed Under: DevOps, Shell Scripting

Examples of “shift” Command in Shell Scripts

By admin

The shift Statement Sometimes a script does not require a specific number of arguments from users. Users are allowed to give as many arguments to the script as they want. In these situations, the arguments of the script are usually processed in a while loop with the condition being (($#)). This condition is true as long as the number of arguments is greater than zero. Within the script $1 and the shift statement process each argument. Because doing a shift reduces the argument number, … [Read more...] about Examples of “shift” Command in Shell Scripts

Filed Under: DevOps, Shell Scripting

Korn Shell select Loop

By admin

The select statement in the Korn shell creates a menu. This construct is for the Korn shell only. The syntax for creating a menu is: select var in list do statement1 ... statementN done The variables var and list follow the same syntactic rules used in the for loop (although the operation of the select loop is substantially different). If the list contains metacharacters, the metacharacters are expanded into file names. The elements in the list are the menu … [Read more...] about Korn Shell select Loop

Filed Under: DevOps, Shell Scripting

How to use “break” and “continue” statements in shell scripts

By admin

The break Statement The break statement allows you to exit the current loop. It is often used in an if statement that is contained within a while loop, with the condition in the while loop always evaluating to true. This is useful if the number of times the loop is executed depends on input from the user and not some predetermined number. The break statement exits out of the innermost loop in which it is contained. $ cat break.ksh #!/bin/ksh # Script name: break.ksh typeset -i … [Read more...] about How to use “break” and “continue” statements in shell scripts

Filed Under: DevOps, Shell Scripting

How to use until loop in Shell Scripts

By admin

The until Loop The until loop is very similar to the while loop, except that the until loop executes as long as the command fails. After the command succeeds, the loop exits and execution of the script continues with the statement following the done statement. The syntax for the until loop is: until control_command do statement1 ... statementN done The control_command can be any command that exits with a success or failure status. The statements can be any utility … [Read more...] about How to use until loop in Shell Scripts

Filed Under: DevOps, Shell Scripting

“while” Loop Examples in Shell Scripts

By admin

The while loop allows you to repeatedly execute a group of statements while a command executes successfully. The syntax for the while loop is: while control_command do statement1 ... statementN done where, control_command can be any command that exits with a success or failure status. The statements in the body of the while loop can be any utility commands, user programs, shell scripts, or shell statements. When a while statement is executed, the … [Read more...] about “while” Loop Examples in Shell Scripts

Filed Under: DevOps, Shell Scripting

6 Bash Shell Command Line Chaining Operators in Linux

By admin

Introduction In this article, I will explain you 6 Bash shell command line Chaining Operators (Linux operator). Now let’s discuss what is chaining operator. Chaining operator is something which helps to run multiple commands at once like we execute a script and task completes automatically. Usually, people use Bash shell command line Chaining Operators (Linux operator) in shell scripting but also we can use these operators on shell prompt. Here we are going to discuss on below Bash shell … [Read more...] about 6 Bash Shell Command Line Chaining Operators in Linux

Filed Under: DevOps, Linux, Shell Scripting

Next Page »

Primary Sidebar

Recent Posts

  • How to set the default character set in MySQL and how to propagate it in a master-master replication scenario
  • “Connection reset by peer” – error while ssh into a CentOS/RHEL system with a specific user only
  • MySQL: how to figure out which session holds which table level or global read locks
  • Recommended Configuration of the MySQL Performance Schema
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary