Ana Sayfa / Linux / Bash Script / Hello World Using Variables / Bash Script Üzerinde Değişken Kullanımı

Hello World Using Variables / Bash Script Üzerinde Değişken Kullanımı

Create a new file called with the following content and give it executable permissions with chmod +x

Execute/Run via: ./

#!/usr/bin/env bash

# Note that spaces cannot be used around the `=` assignment operator

# Use printf to safely output the data
printf "Hello, %s\n" "$whom_variable"
#> Hello, World

This will print Hello, World to standard output when executed.

To tell bash where the script is you need to be very specific, by pointing it to the containing directory, normally with
./ if it is your working directory, where . is an alias to the current directory. If you do not specify the directory, bash
tries to locate the script in one of the directories contained in the $PATH environment variable.

The following code accepts an argument $1, which is the first command line argument, and outputs it in a
formatted string, following Hello,.

Execute/Run via: ./ World

#!/usr/bin/env bash
printf "Hello, %s\n" "$1"
#> Hello, World

It is important to note that $1 has to be quoted in double quote, not single quote. “$1” expands to the first
command line argument, as desired, while ‘$1’ evaluates to literal string $1.

Security Note:
Read Security implications of forgetting to quote a variable in bash shells to understand the
importance of placing the variable text within double quotes.

Bunada Göz Atın

PHP Types

Type Comparison There are two types of comparison: loose comparison with == and strict comparison …

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir