Learn Input, Output, and results from the Bash Shell program! - AkuCode


Parameters and variables


Quoting from a manual (bash instructions) that can be seen by typing "man" in your Bash terminal, "parameter A is the entity that holds a value." There are three types of parameters: position parameters, custom parameters, and variable parameters. Position parameters are the arguments that are in the Barus command and they are referenced by numbers. Special parameters are set by the bash shell to store information about aspects of the current state, such as the number of arguments and the exit code of the last command. Its name is non-alphanumeric characters (e.g.: *, #, and _). Variable identified by name.

            The Parameter value is accessed by preceding its name, number, or character with a $ sign such as $3, $ #, or $HOME. The name can also be controlled with curly braces such as $ {10}, $ {PWD}, or $ {USER}.

In the position parameter, the command line argument exists in the Bash program as numbered parameters. The first Argument is $! and the second $2, and so on

Listing 2-1.hello
#: Description: Print the Hello and command the first line argument, by creating code like the one below:
Printf “Hello, %s!\n” “$1”
            Now you can call the script plus an argument to change the output. Here's the result:

When calling the script above without adding an argument the result will be as follows


And when calling with the added argument "John", it looks like this

Shell Bourne can only run up to nine position parameters. If the script uses $10 then it will be interpreted as $1 and followed by zero (0). Bash retains it to still be able to run the old Instant. If the parameter is more than 9 then the amount must be entered in the curly brackets $ {34}.

            Special Parameters *@#0$?_!-, the first two special parameters, $* and $@, expanding the value of all parameters and positions combined. $ # Expands the number of positional parameters. $0 contains the path to the script that is running or to the shell itself if no script is being executed.

$ $ contains a process identification number or commonly referred to as PID of the current process, $? It is set to the exit code of the last executed command, and $ _ is set to the last argument of the prompt. $! It contains the PID of the last command executed in the background, and $-is set to the current flag option.

Variable is a parameter denoted by name; A name is a word that contains only letters, numbers or underscores and starts with a letter or underline. The value can be assigned to a variable with a writing format as follows:

Name = VALUE

Many variables have been set up by the shell itself, including the three you've seen and read: HOME, PWD, and PATH. With only two small exceptions, auto_resume and Histchars, all the variables are set by the shell.

Arguments and Options

The word entered after the command is an argument. This is a word separated by white space (one or more spaces or tabs). If whitespace is escaped or quoted, it no longer separates the word but becomes part of the word.

The command line below has four arguments:

Echo 1 ' 2 3 ' 4 5

echo-n Now  is the time

printf "$% s%sn" one Two Three

On the first line, space between two and three is quoted because it is surrounded by a single quotation mark, and on the second line the space bar has been passed by the backslash line, which is a shell character. In the last row, space is quoted with double quotation marks. In the second command, a first argument is an option. In the old version the option to cancel command is a letter preceded by a hyphen, sometimes followed by an argument.

GNU commands found in Linux distributions should also accept long options. These are words that are preceded by double dashes. For example, most GNU utilities have the usual options called "— version" to display versions:


Comments