Receive all updates via Facebook. Just Click the Like Button Below

Shell Strings

Strings are scalar and there is no limit to the size of a string.
Any characters, symbols, or words can be used to make up your string.

1

Strings in Linux Shell Scripting

2

How to define a string?
We use single or double quotations to define a string.
"Double Quotes" - Anything enclose in double quotes removed meaning of that characters (except \ and $).
'Single quotes' - Enclosed in single quotes remains unchanged.
`Back quote` - To execute command

Example:

 
#!/bin/bash
single='Single quoted'
double="Double quoted"
echo $single
echo $double
            

Save the above example script as quotes.sh
chmod 755 quotes.sh
./quotes.sh

String Formatting

Character Description
-n Do not output the trailing new line.
-e Enable interpretation of the following backslash escaped characters in the strings:
\a alert (bell)
\b backspace
\c suppress trailing new line
\n new line
\r carriage return
\t horizontal tab
\\ backslash

Example:

 
#!/bin/bash
echo -e "Hello \t Welcome to Linux Shell Scripting"
            
3

Related posts:

Advertise here

picture picture

Follow us

picture

- Tech-Tutorials twitter.com/techcuriosity

Like us

About Techcuriosity

I am Telson, the webmaster of Techcuriosity.com and through this site, I share my knowledge and curiosities in the Tech World.


What We Offer

  • What is ..?
  • How to ..?
  • Difference between ..?
  • How .. works?
  • Get in Touch

    techcuriosity@gmail.com
    UK : +44 77 33 890 678

    picture picture

    Our Partners

  • Website Design Dubai
  • SEO Link Exchange
  • picture

    picture