From e954ce4c7f162bded584fd10220d8c679c6a900d Mon Sep 17 00:00:00 2001 From: Kshitij Dwivedi Date: Sat, 30 Oct 2021 02:45:02 +0530 Subject: [PATCH] Enhanced Readability of the File --- ebook/en/content/004-bash-variables.md | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ebook/en/content/004-bash-variables.md b/ebook/en/content/004-bash-variables.md index d21be46..77b6dbb 100644 --- a/ebook/en/content/004-bash-variables.md +++ b/ebook/en/content/004-bash-variables.md @@ -1,6 +1,6 @@ # Bash Variables -As with any other programming language, you can use variables in Bash as well. However, there are no data types, and a variable in Bash can contain numbers and characters. +As in any other programming language, you can use variables in Bash Scripting as well. However, there are no data types, and a variable in Bash can contain numbers as well as characters. To assign a value to a variable, all you need to do is use the `=` sign: @@ -10,29 +10,29 @@ name="DevDojo" >{notice} as an important note, you can not have spaces before and after the `=` sign. -After that, to access the variable, you have to use the `$` and reference it like this: +After that, to access the variable, you have to use the `$` and reference it as shown below: ```bash echo $name ``` -Wrapping the variable name between curly brackets is not required but is considered good practice, and I would advise to use them whenever you can: +Wrapping the variable name between curly brackets is not required, but is considered a good practice, and I would advise you to use them whenever you can: ```bash echo ${name} ``` -The above would output: `DevDojo` as this is the value of our variable. +The above code would output: `DevDojo` as this is the value of our `name` variable. -Next, let's update our `devdojo.sh` script and include a variable. +Next, let's update our `devdojo.sh` script and include a variable in it. -Again, with your favorite text editor, open the file: +Again, you can open the file `devdojo.sh` with your favorite text editor, I'm using nano here to open the file: ```bash nano devdojo.sh ``` -And update the file, so it looks like this: +Adding our `name` variable here in the file, with a welcome message. Our file now looks like this: ```bash #!/bin/bash @@ -42,7 +42,7 @@ name="DevDojo" echo "Hi there $name" ``` -Save it and run it again: +Save it and run the file using the command below: ```bash ./devdojo.sh @@ -54,13 +54,13 @@ You would see the following output on your screen: Hi there DevDojo ``` -Here is a rundown of the script: +Here is a rundown of the script written in the file: -* `#!/bin/bash` - first, we specified our shebang -* `name=DevDojo` - then we defined a variable called `name` and assigned a value to it -* `echo "Hi there $name"` - finally we output the content of the variable on the screen by using `echo` +* `#!/bin/bash` - At first, we specified our shebang. +* `name=DevDojo` - Then, we defined a variable called `name` and assigned a value to it. +* `echo "Hi there $name"` - Finally, we output the content of the variable on the screen as a welcome message by using `echo` -You can also add multiple variables: +You can also add multiple variables in the file as shown below: ```bash #!/bin/bash @@ -71,7 +71,7 @@ greeting="Hello" echo "$greeting $name" ``` -Save it and run it again: +Save the file and run it again: ```bash ./devdojo.sh @@ -83,4 +83,4 @@ You would see the following output on your screen: Hello DevDojo ``` -Note that you don't necessarily need to add semicolon `;` at the end of each line. It would work both ways, a bit like in JavaScript! \ No newline at end of file +Note that you don't necessarily need to add semicolon `;` at the end of each line. It works both ways, a bit like other programming language such as JavaScript!