![]() The backslash 'escapes' the character it is put before. Said,: command not var='he said, echo $varīackslash is like putting single quotes around a single character. Similarly, you can use the single quotes to hide double quotes from the shell. Own villa: command not var="My 'own villa' is echo $var The double quotes can be used to hide single quotes from the shell. Which is not the case with the single quotes. Since dollar sign is not ignored, you can expect variable name to be substituted with its value. Almost because they also tend to ignore all the special characters except: ![]() echo 'how areĭouble quotes work almost similar to single quotes. The enter key is also preserved under single quotes. echo $varīut if you wrap it in single quotes, $ will lose its special power. If you echo the variable name with $, it shows the value of the variable. Ignoring all special charactersĪll special characters lose their meaning if they are enclosed in single quotes. grep 'Steve Waugh' cricketīasically, when the shell see the first single quote, it ignores any special characters (white space is also a special character) until it finds another single quote (closing quotes). When you enclose the arguments in quotes, it is interpreted as a single entity. At the same time, it also shows the result from the file cricket. Since there is no file named Waugh, it throws an error for that. In the above example, it takes Steve as the first argument to grep but Waugh and cricket are taken as the files in which it should preform the search. Why? Because space is used for separating command, options and arguments. This will give you two results: grep Waugh cricketīut if you want to search for Steve Waugh only, and you try using it as it is, you'll see an error: grep Steve Waugh cricket Now, you use grep command to look for cricketers with family name Waugh. Here's a sample text file with some Cricketers from the 90s. Everything between the single quotes is considered one single element. The single quote in Shell ignores all type of special characters in it. There are four different types of quote characters:Įxcept the backlash, the rest of the three characters occur in pair. ![]() I'll explain the different types of quote characters and their usage in shell scripting. The quotes are 'special feature' in Linux shell and it may get confusing, specially if you are new to Linux commands and shell scripting. Handling special characters? You use quotes again. Dealing with spaces in filename? You use quotes. You'll often use quotes in Linux command line. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |