positional parameters

All posts tagged positional parameters by Linux Bash
  • Posted on
    Featured Image
    Positional parameters are variables in a bash script that hold the value of input arguments passed to the script when it is executed. These parameters are automatically assigned by Bash and are named $1, $2, $3, etc., corresponding to the first, second, third, and subsequent arguments. How do you normally access these positional parameters? In a Bash script, you can directly access the first nine parameters using $1 to $9. For example, $1 retrieves the first argument passed to the script, $2 the second, and so on. Beyond the ninth parameter ($9), you cannot directly use $10 to refer to the tenth parameter as Bash interprets it as ${1}0 (i.e., the first parameter followed by a literal '0').
  • Posted on
    Featured Image
    When scripting in Bash, handling multiple parameters dynamically can significantly enhance the flexibility and reusability of your scripts. One common challenge is joining these parameters with a custom delimiter. In this blog, we'll explore how to expand $@, which represents all positional parameters, with custom separators by manipulating the Internal Field Separator (IFS). We'll also provide an executable script demonstrating this technique. Q&A on Using IFS with $@ in Bash Q1: What does $@ mean in a Bash script? A1: In Bash, $@ refers to all the positional parameters passed to the script or function. It lets you access all the arguments given to the script. For example, in ./script.