Mindblown: a blog about philosophy.

  • Shell Scripting getopts options

    The getopts options are used in shell scripts to parse arguments passed to them. When arguments are passed on the command line, getopts parse those arguments instead of command lines. Options are written starting with a hyphen (-), followed by the letter. For example, -a, -b, -c, -d, etc. Example 1 without argument: Look at the…

  • Example:

    We have two files, one is parent file (main.sh) and other is configuration file (config.sh). We have to source this configuration file into our parent file. Script for config.sh Script for main.sh Look at the above snapshot, we’ve included config.sh file with source command. Note: We can also use ( . config.sh ) command instead of ( source config.sh ) . Now on…

  • Shell Scripting Sourcing a config file

    Many programs use external configuration files. Use of external configuration files prevents a user from making changes to a script. Config file is added with the help of source command. If a script is shared in many users and every user need a different configuration file, then instead of changing the script each time simply include the…

  • read command

    The read command allows a user to provide the runtime input. Look at the above snapshot, this is our script using read command. Look at the above snapshot, a user can enter the name in the shell.

  • Shell Scripting Shift Through Parameters

    Shift command is a built-in command. Command takes number as argument. Arguments shift down by this number. For example, if number is 5, then $5 become $1, $6 become $2 and so on. Example: The shift command is mostly used when arguments are unknown. Arguments are processed in a while loop with a condition of ((…

  • Shell Parameters

    Parameters Function $1-$9 Represent positional parameters for arguments one to nine ${10}-${n} Represent positional parameters for arguments after nine $0 Represent name of the script $∗ Represent all the arguments as a single string $@ Same as $∗, but differ when enclosed in (“) $# Represent total number of arguments $$ PID of the script…

  • Shell Script Parameters

    A bash shell script have parameters. These parameters start from $1 to $9. When we pass arguments into the command line interface, a positional parameter is assigned to these arguments through the shell. The first argument is assigned as $1, second argument is assigned as $2 and so on… If there are more than 9 arguments, then tenth or onwards…

  • Hello World script

    Here we’ll write a simple programme for Hello World. First of all, create a simple script in any editor or with echo. Then we’ll make it executable with chmod +x command. To find the script you have to type the script path for the shell. Look at the above snapshot, script echo Hello World is created with echo command…

  • Steps to write and execute a script

    Note: In the last step you have to mention the path of the script if your script is in other directory.

  • Shell Scripting Prevent setuid root spoofing

    Spoofing is a technique through which a user tries to grant unauthorized access on a system by pretending to be the root user. This is called setuid root spoofing. To prevent from spoofing you can add — after #!/bin/bash. It disables further option processing so that shell will not accept any options. Look at the…

Got any book recommendations?