Watching:  

Introduction to Bash Scripting


Author: Subject Coach
Added on: 23rd Jan 2015

 
Please note: You need to login to view this resource

If you are looking for a beginer's course for Bash scripting, This course is very well for you. I've covered some of the most important topics to get you started. Course contents include

  1. Welcome message [Free]
  2. What is Bash
  3. Command line shortcuts and tricks
  4. Getting started with Bash profiles
  5. Bash Expansions
  6. Command Redirection and Piping 
  7. Using Echo and PrintF and how to preventing command expansion
  8. Understanding local and environment variables
  9. Bash script syntax
  10. A basic Bash script
  11. Working with numbers and operators
  12. Working with arrays
  13. Controlling output with awk, grep and cut commands. How to use basic bash color themes with your output.
  14. Working with here document and files
  15. Flow control statements and loops
  16. Introduction to functions
  17. Interacting with user
  18. Closing note

I hope that you will learn heaps from this course, please leave your feedback and improvement suggestions.

 

 

Author: Subject Coach
Added on: 23rd Jan 2015

Please get in touch with your teacher or tutor in case you have a question related to this lesson

None just yet!

In this chapter, we will explore using echo and printF commands and how we can prevent command line expansions.

Echo and printF commands are used to output strings to standard output.

when we echo a string in single quotes, then string is printed literally as is, it doesn't matter if string has $ or backticks in it. If double quotes are used to enclose a string, then $ or backticks and brackets will have special meaning and will be expanded. To disable expansions we escape these special characters with \.

Let's initial a local variable, my var, with value something cool. I can echo this by using echo $myvar. But then if I escape $ with \, then myvar will be printed as is. Notice, we are not using quotes here. Enclosing $myvar in single quotes will have similar effect. However if I try to enclose $myvar within backticks, then I get an error, because myvar is translated to value "something cool" and "something" is not a known command.


Similarly, printF can be used to output strings. PrintF Prints formatted data to standard output. % is format specifier prefix and is followed by specifier itself. to escape % use double %. In this printF command, %s is replaced by $USER value, which in my case is jas. If I escape % with \, it has no effect here on % specifier. I can escape $ with \ however, then $USER will be included in output string as is.

In next chapter, we will learn about variables.