Techniques cited in Unix / Linux

Super characters in Unix / Linux

Shell provides a variety of characters that have special meaning while using them in any Shell script and cause a limit of a word unless quoted.

For example: super characters? connect to a single character while listing files in a folder and super characters * will connect more than one character. The following lists a list of most special characters in the shell (also called super characters).

 * ? [ ] '"$; & () | ^ <> new-line space tab 

A character can be cited by preceding it with a sign.

Example in Unix / Linux:

Here is an example showing how to print a * or a?:

 #! / bin / sh echo Hello ; Word 

It will produce the following result:

 Hello ./ test . sh : line 2 : Word : command not found shell returned 127 

Now we use a quoted character:

 #! / bin / sh echo Hello ; Word 

It will produce results:

 Hello ; Word 

The $ symbol is a metaphor, so it must be cited to avoid the shell from performing special tasks related to it:

 #! / bin / sh echo "I have $ 1200" 

The above code produces the following result:

 I have $ 1200 

There are 4 types of citation patterns listed in the following table:

Quote Description of Single Quote All characters in the middle of this citation are no longer of special significance to the shell. Double quotes Most characters between this citation have no special meaning except the following characters:
  1. $
  2. `
  3. $
  4. '
  5. "
Backslash Any character behind the backslash does not have its special meaning. Reverse quote (``) Any character in the middle of a reverse quote is treated by the shell as a command and run.

Single quotes in Unix / Linux:

We consider an echo command that contains many special characters in the following shell:

 echo <- $ 1500. **>; ( update ?) [ y | n ] 

Putting a backslash () in front of every special character is tedious and makes the code difficult to read.

 echo < - $ 1500 . **>; (update?) [y | n] 

There is an easy way to quote a large group of characters. We place a single citation (`) at the beginning and end of the string:

 echo '; (update?) [y | n] ' 

Any character in a single citation is quoted as having a backslash before each character. Therefore, now each echo command is displayed correctly.

If a single citation appears in a string to create the output, you should not place the entire string in the single citation, instead you should precede them with the following:

 echo 'It's Shell Programming' 

Double quotes in Unix / Linux

You are trying to run Shell script later. This script uses single quotes:

 VAR = ZARA echo '$ VAR owes ; [as of (`date +% m /% d`)] ' 

It will produce the following result:

 $ VAR owes <- $ 1500. **>; [ as of ( `date +% m /% d` ) ] 

But it's not what you want to display. So it is clear that a single quote prevents the variable replacement. If you want to replace the value of the variable and perform the following comma as you would expect, then you need to place your commands in the double quote as follows:

 VAR = ZARA echo "$ VAR owes ; [as of (` date +% m /% d`)] " 

It will produce the following result:

 ZARA owes <- $ 1500. **>; [ as of ( 07/02 ) ] 

Double quotes eliminate the special meaning of all special characters except the following:

$ for parameter substitution

Reverse quote for command replacement

$ is represented by the letter of the dollar sign

`represents in words of reverse quotation marks

"allows embedded double quotes

Allows embedded backslash characters

All other "characters" are represented by its literal meaning (not specifically)

Any character in a single citation is cited as a backslash in the preceding section of each character. So now this echo command is displayed correctly.

If a single citation appears in a string in the output, you should not place the entire string in a single citation, but instead you should put it backwards as follows:

 echo 'It's Shell Programming' 

Quoted back in Unix / Linux

By placing any shell command in the middle of the citations, the shell will execute that command.

Syntax

This is a simple syntax for placing any Shel l command in the middle of a reverse quote:

For example:

 var = `command` 

For example:

Here we will run the date command and keep the result in the DATA variable:

 DATE = `date` echo " Current Date: $ DATE " 

It results in:

 Current Date : Thu Jul 2 05:28 : 45 MST 2009 

According to Tutorialspoint

Previous article: Shell replacement

Next article: Navigation IO in Unix / Linux

5 ★ | 1 Vote

May be interested

  • Basic utilities: print, email in UnixBasic utilities: print, email in Unix
    by this chapter, you have a few basic insights about unix systems and some of its basic commands. this chapter will briefly discuss some of the basic but important utilities of unix utilities that you will use in your daily activities.
  • User management in Unix / LinuxUser management in Unix / Linux
    unix supports a concept of group account, which groups a number of accounts logically. each account will be part of any group account. the unix team plays an important role in executing process management and allowing access to files.
  • Use variables in ShellUse variables in Shell
    a variable is a string of characters from which we assign a value. the assigned value can be a number, text, file name, device or any other type of data.
  • Micro editor in Unix / LinuxMicro editor in Unix / Linux
    there are many ways to edit files in unix and for me, one of the best ways is to use the editor to edit the micro screen orientation. this editor lets you edit the lines of content with other lines in the file.
  • C Shell operatorsC Shell operators
    this tutorial lists all the operators available in c shell. here, most operators are similar to those we have in the c programming language.
  • Control loop in Unix / LinuxControl loop in Unix / Linux
    the previous chapter has been shown how to create loops and work with them to perform various tasks. sometimes you need to stop a loop or continue their repetitive process.
  • What is a shell?What is a shell?
    shell is an environment in which we can run commands, programs and shell scripts. there are different versions of shell, which differ only from the version of the operating system. each version of shell has its own set of recognized commands and functions.
  • ManPage Help in UnixManPage Help in Unix
    all unix commands come with arbitrary and mandatory functions. it is very common when you forget the full syntax of these commands.
  • Korn Shell OperatorKorn Shell Operator
    this tutorial lists all the operators available in the korn shell. here most of these operators are similar to what we have in the c program language.
  • Manage folders in Unix / LinuxManage folders in Unix / Linux
    a directory is a file whose only task is to store the name and related file information. all files, which can be regular, special or directory files, are kept in folders.